Dynamically resize fragment in android -
i have fragment fill of screen. now, if add new fragment each fragment fill half of screen. how can this?
i tried layout , programmatically added fragments. doesn't work.
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:paddingbottom="@dimen/activity_vertical_margin" tools:context="tech.test.org.game.game$placeholderfragment"> <relativelayout android:id="@+id/relativelayout" android:layout_width="match_parent" android:layout_height="0px" android:layout_weight="50"> </relativelayout> <relativelayout android:id="@+id/relativelayout2" android:layout_width="match_parent" android:layout_height="0px" android:layout_below="@+id/relativelayout" android:layout_weight="50" > </relativelayout> </relativelayout>
thanks.
the answer given kat-hat correct takes load, load ui may hamper performance.
<relativelayout android:id="@+id/relativelayout" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="0.5" > </relativelayout> <relativelayout android:id="@+id/relativelayout2" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="0.5" android:visibility="gone" > </relativelayout> </linearlayout>
when adding second fragment programatically set layout2 visibility visible.
findviewbyid(r.id.relativelayout2).setvisibility(view.visible);
Comments
Post a Comment