2013-02-23 4 views

Antwort

3

Wie ich weiß nicht Kompass Position ändern kann, aber Sie können es deaktivieren und Ihre privaten bauen.

See example here

+0

+1 Interessant. Mal sehen, ob irgendjemand einen Workaround hat, wenn nicht der Kredit ganz Ihnen gehört. – capdragon

+0

Aber das verwendet MapView. Irgendeine Idee mit MapFragment? –

1

Ich weiß, dass es eine lange Zeit gewesen ist, dass die Frage wurde gefragt, aber ich feld zu diesem Thema ein paar Tagen habe ich vor behob das Problem wie folgt:

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 diesem Beispiel legte ich den Kompass in der Ecke rechts. Sie müssen sicherstellen, dass Ihr mapFragment erstellt wird, wenn Sie dies tun, ich schlage vor, dass Sie Ihren Code in der Methode "onMapReady" Ihrer MapFragment ausführen.

+1

Dies ist auf der linken Seite aus irgendeinem Grund platziert! – 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

Padding-basierte Lösungen für kleine Verschiebungen, aber soweit ich weiß, gibt es keine API ausgesetzt, die uns kräftig ermöglicht die horizontale „Dichte“ des Kompass ändern von links nach rechts, wie die Lager Google Maps App tut:

enter image description here

Beachten Sie, wenn Sie eine große Menge von links padding angewendet, um den Kompass nach rechts in Ihrer eigenen App, das Google-logo in der linken unteren ebenfalls nach rechts verschoben werden, würde sich zu bewegen über.

0

Auf 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 
    }