我有一個SurfaceView和MapView的應用程序。它們以單個視圖顯示,如下所示:合成Android MapView和SurfaceView
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="XXXXXXXXredactedXXXXXXXXXXXXx"
/>
<class.that.extends.SurfaceView
android:id="@+id/surfaceview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00000000"
/>
</RelativeLayout>
注意MapView出現在SurfaceView之前。正因爲如此,MapView被繪製在「SurfaceView下」,我看到的所有圖像都是黑色的背景,以及我在SurfaceView上繪製的東西。如果我交換順序,並將SurfaceView放在第一個文件和第二個MapView中,則繪製MapView,而不顯示任何SurfaceView。
表面是Z-排序使得它是窗口保持其SurfaceView後面; SurfaceView在其窗口中打出一個孔以允許其表面顯示。視圖層次結構將負責正確地合成Surface中通常出現在其上的任何SurfaceView的同胞。
對我來說,這意味着我應該能夠將SurfaceView放在文件中,讓它「穿透」MapView並顯示它的內容。但是,事實上,它們似乎是兩種觀點,一次只能看到一種觀點。
後想:我試着將背景設置爲#00000000,以便背景的alpha值爲零(即透明),但它沒有任何影響。