2013-02-23 2 views

답변

3

난 당신이 나침반 위치를 변경할 수 있지만, 당신이 그것을 해제하고 당신에게 개인 하나를 구축 할 수 있습니다 아시다시피.

See example here

+0

+1 흥미 롭습니다. 누군가가 해결 방법을 제시하는지 보자. 그렇지 않으면 크레딧이 모두 당신 것이 아니다. – capdragon

+0

그러나 MapView를 사용하고 있습니다. MapFragment에 대한 아이디어가 있습니까? –

1

나는 문제가 아니 었 느냐는 오랜 시간이 지났 알고 있지만, 내가 몇 일 전에이 문제에 대한 FELD I 다음과 같이 문제를 해결했습니다.

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가 작성되었는지 확인해야합니다. MapFragment의 "onMapReady"메소드에서 코드를 실행하는 것이 좋습니다.

+1

인데 이것은 bottm left rof에 배치됩니다! – Paschalis

7
@Override 
public void onMapReady(GoogleMap map) { 

    try { 
     final ViewGroup parent = (ViewGroup) mMapView.findViewWithTag("GoogleMapMyLocationButton").getParent(); 
     parent.post(new Runnable() { 
      @Override 
      public void run() { 
       try { 
        Resources r = getResources(); 
        //convert our dp margin into pixels 
        int marginPixels = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, r.getDisplayMetrics()); 
        // Get the map compass view 
        View mapCompass = parent.getChildAt(4); 

        // create layoutParams, giving it our wanted width and height(important, by default the width is "match parent") 
        RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(mapCompass.getHeight(),mapCompass.getHeight()); 
        // position on top right 
        rlp.addRule(RelativeLayout.ALIGN_PARENT_LEFT, 0); 
        rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP); 
        rlp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); 
        rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 0); 
        //give compass margin 
        rlp.setMargins(marginPixels, marginPixels, marginPixels, marginPixels); 
        mapCompass.setLayoutParams(rlp); 
       } catch (Exception ex) { 
        ex.printStackTrace(); 
       } 
      } 
     }); 
    } catch (Exception ex) { 
     ex.printStackTrace(); 
    } 

} 
0

패딩 기반 솔루션은 작은 오프셋을 작동하지만 내가 아는 한 주식 구글지도 앱처럼 왼쪽에서 오른쪽으로 우리가 견고 나침반의 수평 "중력"를 변경할 수 있습니다 노출 어떤 API가 없습니다 하지 : 당신이 당신의 자신의 응용 프로그램에서 오른쪽으로 나침반을 이동 왼쪽 패딩의 큰 금액을 적용하는 경우, 왼쪽 아래에있는 Google 로고도 오른쪽으로 이상 이동 될 것

enter image description here

하는 것으로.

0

지도에서 2.0 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 
    } 
관련 문제