Android: Google Maps API - Change position of maps toolbar

风流意气都作罢 提交于 2019-11-26 10:01:59

问题


I\'m using the Google Maps API for Android. The following code enables the maps toolbar in the bottom right corner when I click on a Marker

googleMap.getUiSettings().setMapToolbarEnabled(true); 

However, I\'d like this maps toolbar to appear in the TOP RIGHT corner of the map, rather than the default bottom right position.

How would I do this?


回答1:


Thought of commenting, But has low reputation. So:

As far as I know, there is no way to position it for now. It'll appear at its default position only.

As Nathan said I should add some alternative if possible. So,There is a work around: You can disable the map's toolbar. and can add appcompact's ToolBar anywhere in the layout.

Reference : https://developer.android.com/reference/android/support/v7/widget/Toolbar.html




回答2:


This is an answer that i came across before as to how to move the toolbar to the bottom of the page. I hope this helps you.

//get reference to my location icon
    View locationButton = ((View) mapFragment.getView().findViewById(Integer.parseInt("1")).
            getParent()).findViewById(Integer.parseInt("2"));

    // and next place it, for example, on bottom right (as Google Maps app)
    RelativeLayout.LayoutParams rlp = (RelativeLayout.LayoutParams) locationButton.getLayoutParams();
    // position on right bottom
    rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
    rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    rlp.setMargins(0, 0, 30, 30);

EDIT: As per suggestions (of @Andro) this is the code to change the location of the map toolbar:

//get reference to my location icon

 View toolbar = ((View) mapFragment.getView().findViewById(Integer.parseInt("1")).
            getParent()).findViewById(Integer.parseInt("4"));

    // and next place it, for example, on bottom right (as Google Maps app)
    RelativeLayout.LayoutParams rlp = (RelativeLayout.LayoutParams) toolbar.getLayoutParams();
    // position on right bottom
    rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
    rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    rlp.setMargins(0, 0, 30, 30);


来源:https://stackoverflow.com/questions/28688470/android-google-maps-api-change-position-of-maps-toolbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!