我有一个针对Fragment(android.support.v4.app.Fragment)的xml布局。当第一次添加此Fragment时,背景drawable显示正常。但当这个Fragment被替换为另一个Fragment,然后再次替换回来(通过创建一个新实例并使用FragmentTransaction.replace()),背景drawable消失了(但不是所有情况都是如此,请参见下文)。以下是该Fragment的布局xml:
<?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>
所讨论的背景可绘制对象位于具有id“pageLayout”的RelativeLayout中。
可能的线索:
- 当我删除其中的ImageView时,背景可绘制对象正常显示。 - 其他片段具有类似的布局xml(具有相同的背景可绘制对象),但其中没有ImageView,并且它们可以正常工作。 - 这些片段中的一个具有WebView和按钮,这个的背景也能正常显示。 - 将“WebView片段”替换为所讨论的片段后,背景正常显示(!?)。
编辑:如果将图像加载到ImageView中,然后在其上启动对话框主题活动,然后完成,则会始终出现相同的问题。我下面的解决方案可以解决这两种情况。