我不知道 Pokémon GO 是如何做到的,但你可以通过一些布局技巧获得非常漂亮的效果。我正在使用天空图像,并使用渐变视图(模拟地平线)覆盖天空图像和地图,并使用半透明绿色视图覆盖地图。
activity_maps.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="170dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/sky"/>
<View
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_alignParentBottom="true"
android:background="@drawable/gradientsky"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="mypackage.MapsActivity"/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#2200ff00"/>
<View
android:layout_width="match_parent"
android:layout_height="20dp"
android:background="@drawable/gradientmap"/>
</RelativeLayout>
</LinearLayout>
gradientsky.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="90"
android:startColor="#ffffff"
android:endColor="#00ffffff" />
</shape>
gradientmap.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="270"
android:startColor="#ffffff"
android:endColor="#00ffffff" />
</shape>
MapsActivity.java(微不足道,但我添加它是为了示例完整)
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap map) {
map.getUiSettings().setCompassEnabled(false);
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(39.87266,-4.028275))
.zoom(18)
.tilt(67.5f)
.bearing(314)
.build();
map.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
}
结果如下:
另一种方法是使用 TileOverlay 来显示自定义地图。您可以找到有关 Tile Overlays 的更多信息here。
为了改进示例,您可能需要为天空添加一些视差效果,以便在地图旋转时移动。