Mar*_*lon 10 android google-maps transparent android-mapview google-maps-android-api-2
我正在开发一个地图应用程序.我想在MapView下显示一些视图.我正在使用这个方法:
mapView.setAlpha(0.5f);
Run Code Online (Sandbox Code Playgroud)
mapView没有任何反应.当我尝试将此方法应用于我的按钮时,它工作正常,即使将其应用于mapView的父视图,每个子视图都会透明,除了mapView.
我们怎样才能使mapView透明化?我在这里查看了其他问题,似乎无法找到解决方案.
我们可以使用mapView.getMap()中的一些特殊方法使其透明吗?
您可以使用View.setAlpha()(文档)设置地图的透明度.这是一个工作示例:
activity_maps.xml:
<RelativeLayout
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">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="THIS TEXT IS VISIBLE"
android:textSize="24sp"
android:gravity="center"/>
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
MapsActivity.java
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback{
@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) {
Marker m = googleMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
m.showInfoWindow();
View v = getSupportFragmentManager().findFragmentById(R.id.map).getView();
v.setAlpha(0.5f); // Change this value to set the desired alpha
}
}
Run Code Online (Sandbox Code Playgroud)
结果如下所示(因为您看到文本因地图的透明度而可见):
| 归档时间: |
|
| 查看次数: |
2612 次 |
| 最近记录: |