Google maps 谷歌地图android api:移动指南针按钮

Google maps 谷歌地图android api:移动指南针按钮,google-maps,google-maps-android-api-2,Google Maps,Google Maps Android Api 2,我发现可以为UI设置边距,也可以禁用按钮 但是我们可以将指南针按钮移动到其他位置而不是左上角吗? 谷歌地图应用程序在右上角有它,这让我觉得这是可能的。我也在努力解决这个问题。我的设计师们以谷歌地图为例,但我还没有找到一种方法来做到这一点。我所看到的最接近的是JCDecary的反应,他将按钮移动到底部的左角。不过,这取决于一个命名标签,这让我感到厌倦,因为谷歌可能会决定在任何时候改变它。我只是遇到了同样的问题,并这样解决了它: /* access compass */ ViewGroup pare

我发现可以为UI设置边距,也可以禁用按钮

但是我们可以将指南针按钮移动到其他位置而不是左上角吗?


谷歌地图应用程序在右上角有它,这让我觉得这是可能的。

我也在努力解决这个问题。我的设计师们以谷歌地图为例,但我还没有找到一种方法来做到这一点。我所看到的最接近的是JCDecary的反应,他将按钮移动到底部的左角。不过,这取决于一个命名标签,这让我感到厌倦,因为谷歌可能会决定在任何时候改变它。

我只是遇到了同样的问题,并这样解决了它:

/* access compass */
ViewGroup parent = (ViewGroup) mMapView.findViewById(Integer.parseInt("1")).getParent();
View compassButton = parent.getChildAt(4);
/* position compass */
RelativeLayout.LayoutParams CompRlp = (RelativeLayout.LayoutParams) compassButton.getLayoutParams();
CompRlp.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
CompRlp.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
CompRlp.setMargins(0, 180, 180, 0);
这将使指南针在2.0 map api上离顶部稍微远一点

    // change compass position 
if (mapView != null &&
        mapView.findViewById(Integer.parseInt("1")) != null) {
    // Get the view
    View locationCompass = ((View) mapView.findViewById(Integer.parseInt("1")).getParent()).findViewById(Integer.parseInt("5"));
    // and next place it, on bottom right (as Google Maps app)
    RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)
            locationCompass.getLayoutParams();
    // position on right bottom
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
    layoutParams.setMargins(0, 160,30, 0); // 160 la truc y , 30 la  truc x
}

我修复了如下问题:

try {
                assert mapFragment.getView() != null;
                final ViewGroup parent = (ViewGroup) mapFragment.getView().findViewWithTag("GoogleMapMyLocationButton").getParent();
                parent.post(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            for (int i = 0, n = parent.getChildCount(); i < n; i++) {
                                View view = parent.getChildAt(i);
                                RelativeLayout.LayoutParams rlp = (RelativeLayout.LayoutParams) view.getLayoutParams();
                                // position on right bottom
                                rlp.addRule(RelativeLayout.ALIGN_PARENT_LEFT, 0);
                                rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP,0);
                                rlp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                                rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
                                rlp.rightMargin = rlp.leftMargin;
                                rlp.bottomMargin = 25;
                                view.requestLayout();
                            }
                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }
                    }
                });
            } catch (Exception ex) {
                ex.printStackTrace();
        }
试试看{
断言mapFragment.getView()!=null;
final ViewGroup parent=(ViewGroup)mapFragment.getView().findViewWithTag(“GoogleMapMyLocationButton”).getParent();
parent.post(新的Runnable(){
@凌驾
公开募捐{
试一试{
for(int i=0,n=parent.getChildCount();i
在这个例子中,我把指南针放在右边的角落里。您需要确保在执行此操作时创建了mapFragment,我建议您使用mapFragment的“onMapReady”方法运行代码