I have an activity with two fragments like this image : status A Fragment B is a ListFragment. When user clicks on one row in fragment B. I have show detail. And the UI should like this: status B
How can I move and resize fragment B?
I tried this way but don't know whether it is a correct way or hacky way. I set this layout for the activity.
<LinearLayout
android:id="@+id/linearLayoutMainPart"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/scrollViewBottomMenu"
android:layout_toRightOf="@+id/scrollViewLeftMenu"
android:background="@android:color/white"
android:orientation="horizontal" >
<FrameLayout
android:id="@+id/leftContainer"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
</FrameLayout>
<FrameLayout
android:id="@+id/rightContainer"
android:layout_width="0dip"
android:layout_height="match_parent">
</FrameLayout>
</LinearLayout>
I create 3 fragment A, B, C class. When the activity create I add two fragment A, B to leftContainer and rightContainer. (fragment A layout width is fixed). When user click on one row in fragment B. I replace fragment A by another instance of fragment B (with different layout, and using the same data with the old fragment B instance). And replace fragment B in rightContainer by an instance of fragment C.
In fragment B class. I have flag to choose layout when onCreateView method is called, something like :
if(rightPosition)
return B_right_pos_layout;
else
return B_left_pos_layout;
I think I can use the same instance of Fragment B. By doing like this :
FragmentB fragmentB = (FragmentB) getSupportFragmentManager().findFragmentByTag(FRAGMENT_B_TAG);
fragmentB.setRightPos(false);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(rightContainer, fragmentC);
transaction.replace(leftContainer, fragmentB);
transaction.commit();
I think this way is more like a hack way. What is the best way?