0

私はしばらく探していましたが、フラグメントを非表示にするときに空きスペースを残さない方法しか思いつきませんでした。3 パネル アプリケーションを使用していますが、そのうちの 1 つを非表示にしても、残りのパネルは同じサイズのままにしたいと考えています。

ここに私の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();

}

どんな助けでも歓迎されます

4

1 に答える 1

0

おそらく、各フラグメントを線形レイアウトなどのコンテナーでラップし、レイアウトの重みをそれに転送できると思います。たとえば、FragmentA を次のようにラップします。

<LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
         android:layout_weight="1"
        android:orientation="horizontal">
        <fragment
            android:name="tets.twopane.FragmentA"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/titles"
            >
        </fragment>
 </LinearLayout>
于 2013-03-15T02:32:33.100 に答える