-1

First i have opened fragment for taking images from camera after taking images display images on another fragment .

But my problem when i open again new fragment by adding then it display first fragment and added new fragment both

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/searchuserLayout"
    android:background="@color/white"
       android:clickable="true">
<RelativeLayout 
    android:id="@+id/backButtonRL"
    android:layout_width="fill_parent"
    android:layout_height="30dp"
    android:layout_alignParentTop="true"
   android:background="@color/action_bar">
      <TextView
        android:id="@+id/backTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerInParent="true"
        android:layout_centerVertical="true"
        android:gravity="left"
        android:layout_marginLeft="10dp"
        android:text="@string/selfie.cancel"
        android:textColor="@color/white" />
       <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_centerVertical="true"
        android:gravity="left"
        android:textStyle="bold"
        android:text="@string/searchFragment_usersearch"
        android:textColor="@color/black" />
        <TextView
        android:id="@+id/done"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerInParent="true"
        android:layout_centerVertical="true"
        android:gravity="left"
        android:layout_marginRight="10dp"
        android:text="@string/done"
        android:textColor="@color/white" />

   </RelativeLayout>
    <customview.ScrollDetectableListView
        android:id="@+id/searchlistView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/backButtonRL"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_gravity="center_horizontal"
         android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginBottom="5dp"
        android:divider="@color/white"
        android:dividerHeight="1sp"/>
</RelativeLayout>
Amrut
  • 2,655
  • 3
  • 24
  • 44
Ganesh Gudghe
  • 1,327
  • 1
  • 17
  • 41

2 Answers2

1

Sometimes, Fragment overlap issue occurs when we try to use the different type of fragments( i.e using support fragment's in few fragments and normal fragments in some other fragment ).

Also try setting a background color to your fragment in XML file.

Amrut
  • 2,655
  • 3
  • 24
  • 44
0

This happens if you are Using addFragment(); instead of replaceFragment(); during the transaction.this is due to fact that the new fragment will be added above the old one(the old one remains as it is).

So to avoid it you can add a Background(either a color or an image) to your Fragment's view (layout). This will prevent the visibility of fragment below.

You may also see THIS ANSWER for reference.

Community
  • 1
  • 1
Anirudh Sharma
  • 7,968
  • 13
  • 40
  • 42
  • i have added background color also but it shows me both fragment – Ganesh Gudghe Sep 01 '15 at 11:33
  • could you please post the xml for both the fragments and also u can use Replace instead of add. – Anirudh Sharma Sep 01 '15 at 11:34
  • `SearchUserPollTimeFragment fragment2 = new SearchUserPollTimeFragment(); FragmentManager fragmentManager = getFragmentManager(); Fragment currentFragment = fragmentManager.findFragmentById(R.id.frame_container); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.hide(currentFragment); fragmentTransaction.setCustomAnimations(R.anim.fadein_anim, R.anim.fadeout_anim,R.anim.fadein_anim, R.anim.fadeout_anim); fragmentTransaction.add(R.id.frame_container,fragment2); fragmentTransaction.commit();` – Ganesh Gudghe Sep 01 '15 at 11:35
  • i am hidding current fragment and adding new one – Ganesh Gudghe Sep 01 '15 at 11:40
  • please post the xml for the fragments. – Anirudh Sharma Sep 01 '15 at 11:50
  • try height = match_parent and also post xml for another frag (only post the root layout ,no need for whole xml) – Anirudh Sharma Sep 01 '15 at 12:05