雖然我覺得這種方法很奇怪,但您應該檢查這些視圖的父容器。
如果它是LinearLayout,那麼難怪View不會覆蓋WebView。 如果你想用戶佈局,嘗試使用RelativeLayout的和相同的對位元件,例如,增加了兩種觀點:
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
另一種變體(更正確IMO)是使用ViewSwitcher,或ViewFlipper。它在showNext(),showPrevious()(在ViewFlipper中)和getNextView()(在ViewSwitcher中)方法之間切換。真的很容易實現和使用。查找一些例子。
只是一個快速提示:
<!-- ViewSwitcher or ViewFlipper -->
<ViewSwitcher
android:id="@+id/view_switcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<View
android:scrollbars="none"
android:id="@+id/id_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<WebView
android:scrollbars="none"
android:id="@+id/id_webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</ViewSwitcher>
而且,在你的代碼:
// This will hide currently displayed and reveal next
((ViewSwitcher) findViewById(R.id.view_switcher)).getNextView();
// Or, in case of ViewFlipper:
// This will hide currently displayed and reveal next
((ViewFlipper) findViewById(R.id.view_switcher)).showNext();
這兩者之間的區別是,切換隻能有2個孩子,並有鑑於工廠創建。
P.S.混合兩個動畫師,編輯後。