【问题标题】:Moving UI Controls of GoogleMap, while not moving the visible region移动 GoogleMap 的 UI 控件,同时不移动可见区域
【发布时间】:2013-12-05 16:18:16
【问题描述】:
我想将 android 中 GoogleMap 的 mylocation-Button 从显示屏的右上角移动到右下角。
android APIs 提供此功能来执行此操作。
GoogleMap.setPadding(int left,int top,int right,int bottom)
我的问题是
所以当用户点击“myLocation”-Button后,用户的位置就不再在地图的中心了。
移动 UI 控件但不填充可见区域的最佳方法是什么?
感谢任何帮助!
【问题讨论】:
标签:
android
android-layout
android-fragments
android-maps-v2
【解决方案1】:
GoogleMap.set padding() 似乎只有在想要拆分屏幕以便地图只覆盖其中一部分时才有意义。
所以我解决这个问题的方法是创建我自己的 my-location 按钮来响应这样的点击:
Layout.xml
<Button
android:id="@+id/myLocation"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="@drawable/button_my_position" />
实现onLocationChanged(),以便我始终可以访问我当前的位置
@Override
public void onLocationChanged(Location location) {
this.currentLocation = location;
}
我的位置点击监听器:
myPosition = (Button)getView().findViewById(R.id.myLocation);
myPosition.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
map.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(currentLocation
.getLatitude(), currentLocation.getLongitude())));
}
});