谷歌地图溢出就像在foursquare应用程序中

时间:2016-06-01 17:46:46

标签: android google-maps android-layout gradient

我正在尝试将地图集成在我的Android应用程序中,就像在foursquare中一样。我需要使地图的一部分透明,然后用文字覆盖。有谁知道怎么做?

以下是一个例子:

Example is presented here.

1 个答案:

答案 0 :(得分:4)

您可以使用RelativeLayout并设置渐变背景来执行此操作:

<强> 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>

<强> gradient.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 (琐碎,但完成示例)

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

结果如下:

enter image description here