I have an xml layout for a Fragment (android.support.v4.app.Fragment). When this Fragment is added for the first time, the background drawable displays fine. But when this Fragment is replaced with another Fragment, then later replaced back in again (by creating a new instance and using FragmentTransaction.replace()), the background drawable disappears ( but not in all cases , see below). Here is the layout xml for the Fragment:
<?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>
The background drawable in question is in the RelativeLayout with the id "pageLayout".
Possible clues:
EDIT: The same issue consistently occurs if an image is loaded into the ImageView then a dialog-themed activity is launched on top of it, then finished. My solution below fixes both cases.
Found a better solution than my last one. In onResume() for the Fragment, just need to do:
getView().post(new Runnable() {
@Override
public void run() {
View v = getView();
if (v != null)
v.invalidate();
}
});
It causes a flicker, but at least it seems to work consistently.
i had a similar problem. With a relativelayout, there was an imageView and a textView. I resolved with a call to bringToFront method:
myImageView.bringToFront();
Hope this helped.
Okay, I fixed this issue while trying to fix another issue. The issue was solved by calling setLayoutParams() on the page
ImageView (with whatever layout params). This caused the background of the pageLayout
RelativeLayout to show up again. The cause of the issue remains unknown...
The fragments are replaced , along with their background, which means that
when a fragment A is replaced by fragment B, the background changes to the background of fragment B.
If you don't give any background to fragment B, then you can see fragment B over fragment A.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.