我有一個用於Fragment(android.support.v4.app.Fragment)的xml佈局。當第一次添加此片段時,背景可繪製顯示正常。但是當這個片段被另一個片段替換,然後再次替換回來(通過創建一個新實例並使用FragmentTransaction.replace()),背景可繪製消失(,但不是所有情況下均爲,見下文)。下面是片段的佈局XML:Android:RelativeLayout背景可繪製消失
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include layout="@layout/footer_photos" />
<RelativeLayout
android:id="@+id/pageLayout"
android:background="@drawable/body_background2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@id/footer">
<ImageView
android:id="@+id/page"
android:layout_height="500dp"
android:layout_width="400dp"
android:layout_centerInParent="true"
android:background="#FFF" />
</RelativeLayout>
</RelativeLayout>
有問題的背景繪製在RelativeLayout的id爲「頁面佈局」。
可能的線索:
- 當我刪除在那裏的ImageView,背景繪製顯示了罰款。
- 其他碎片具有相似的佈局xmls(具有相同的背景可繪製),但沒有ImageViews在裏面,他們工作正常。
- 其中的一個碎片有一個WebView和其中的按鈕,並且這個背景顯示正常。
- 用有問題的片段替換「WebView片段」後,背景顯示正常(!?)。
編輯:如果一個圖像加載到ImageView然後一個對話框主題的活動在它上面啓動,然後完成相同的問題始終發生。我的解決方案解決了這兩種情況。
我認爲使用獨立的ImageViews而不是使用android:background屬性可以解決問題。 – Ken