2016-06-01 5 views
2

Ich versuche, Karte in meine Android App ähnlich wie in foursquare zu integrieren. Ich muss einen Teil der Karte transparent machen und dann mit Text abdecken. Weiß jemand, wie man das macht? HierGoogle Karte Überlauf wie in foursquare App

ein Beispiel:

Example is presented here.

Antwort

4

Sie tun können, es einen RelativeLayout verwenden und einen Gradienten Hintergrund einstellen:

activity_maps.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <fragment 
     android:id="@+id/map" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:name="com.google.android.gms.maps.SupportMapFragment" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@drawable/gradient" 
     android:padding="8dp" 
     android:text="Your layout here" 
     android:gravity="left|center_vertical" /> 

</RelativeLayout> 

Gradienten. xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 

    <gradient 
     android:startColor="#ffffff" 
     android:endColor="#00ffffff" /> 

</shape> 

MapsActivity.java (trivial, aber vervollständigt das Beispiel)

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { 
    private GoogleMap mMap; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_maps); 

     ((SupportMapFragment) getSupportFragmentManager() 
       .findFragmentById(R.id.map)).getMapAsync(this); 
    } 

    @Override 
    public void onMapReady(GoogleMap googleMap) { 
     mMap = googleMap; 
     Marker m = mMap.addMarker(new MarkerOptions().position(new LatLng(40, -4))); 
    } 
} 

Das Ergebnis sieht wie folgt aus:

enter image description here

+0

Dank ist dies sehr hilfreich – Nikola