How to move the Android Google Maps API Compass Position

前端 未结 7 1582
太阳男子
太阳男子 2020-12-05 13:57

Does anyone know if you can change the compass position within the map?

All I can find is how to enable or disable it. But I need to move it down a bit so my overlay

7条回答
  •  醉酒成梦
    2020-12-05 14:42

    I know it's been a long time that the question was asked , but I feld on this issue a few days ago I fixed the problem like this :

    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();
                }
    

    in this exemple i put the compass in the corner right. You need to be sure that your mapFragment is created when you do this, i suggest you run your code in the method "onMapReady" of your MapFragment.

提交回复
热议问题