我一直在寻找一段时间,只是想出了在隐藏片段时不留下开放空间的方法。我有一个 3 面板应用程序,当我隐藏其中一个面板时,我希望其余面板保持相同大小。
这是我的xml代码:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:id="@+id/fragment_container"
android:background="#140506">
<fragment
android:name="tets.twopane.FragmentA"
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="@+id/titles"
android:layout_weight="1"
>
</fragment>
<LinearLayout
android:layout_width="5dp"
android:layout_height="match_parent"
android:orientation="horizontal">
</LinearLayout>
<fragment
android:name="tets.twopane.FragmentB"
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="@+id/viewers"
android:layout_weight="1"
>
</fragment>
<LinearLayout
android:layout_width="5dp"
android:layout_height="match_parent"
android:orientation="horizontal">
</LinearLayout>
<fragment
android:name="tets.twopane.FragmentC"
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="@+id/pass"
android:layout_weight="1"
>
</fragment>
</LinearLayout>
这是我的主要活动中隐藏片段的功能:
public void Hide3() {
final FragmentTransaction ft = this.getFragmentManager()
.beginTransaction();
final Fragment myFrag = this.getFragmentManager().findFragmentById(
R.id.pass);
ft.hide(myFrag);
ft.commit();
}
欢迎任何帮助