Nik*_*kar 3 java android google-maps google-maps-android-api-2
我正在使用Google Maps API for Android.单击标记时,以下代码启用右下角的地图工具栏
googleMap.getUiSettings().setMapToolbarEnabled(true);
Run Code Online (Sandbox Code Playgroud)
但是,我希望这个地图工具栏显示在地图的右上角,而不是默认的右下角位置.
我该怎么做?
Met*_*arf 17
这是我之前遇到的关于如何将工具栏移动到页面底部的答案.我希望这可以帮助你.
//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);
Run Code Online (Sandbox Code Playgroud)
编辑:根据(@Andro)的建议,这是更改地图工具栏位置的代码:
//获取我的位置图标的引用
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);
Run Code Online (Sandbox Code Playgroud)
小智 5
评论的想法,但声誉低.所以:
据我所知,暂时没有办法定位它.它只会出现在默认位置.
正如内森所说,如果可能,我应该添加一些替代方案.因此,有一个解决方法:您可以禁用地图的工具栏.并且可以在布局中的任何位置添加appcompact的ToolBar.
参考:https://developer.android.com/reference/android/support/v7/widget/Toolbar.html
归档时间: |
|
查看次数: |
7041 次 |
最近记录: |