1

タブレット アプリのレイアウトの次の構造を指定しました。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clipChildren="false" >

<LinearLayout
    android:id="@+id/placeholderForLeftFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:baselineAligned="false" >

    <RelativeLayout
        android:id="@+id/placeholderFragmentHomeScreen"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="32" >
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/dummy"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="69"
        android:background="#0000" >
    </RelativeLayout>
</LinearLayout>


<LinearLayout
    android:id="@+id/mainLinearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:baselineAligned="false"
    android:clipChildren="false" >

    <RelativeLayout
        android:id="@+id/invisbleRelativeLayout"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="32"
        android:background="#0000" >
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/placeholderFragmentHotelResultList"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="42"
        android:background="#F0FFFF" >
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/placeholderFragmentHotelDetailScreen"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="26" >
    </RelativeLayout>
</LinearLayout>

最初の LinearLayout には、左側にフラグメントのみが含まれており、移動できません。2 番目の LinearLayout には、最初の位置に非表示の要素があります。これは、他の 2 つの R.Layouts を左にスワイプすると減少し、後ろにスワイプすると増加します。中央の RelativeLayout は常に幅を維持し、最初の LinearLayout で 2 番目と 3 番目をスワイプできます。実際には、2 番目と 3 番目の R.Layout は同じ幅にする必要がありますが、3 番目のレイアウトは画面の境界で 26% しか表示されないはずです。

私が今やりたいことは、3 番目の R.Layout が最初 (アプリの開始直後) から 2 番目のレイアウトと同じ幅を持ち、彼の位置が半分オフスクリーンになっていることです。私がやろうとしたことは、3 つすべての R.Layouts の合計から幅を持つレイアウトを作成し、その中にレイアウトを配置することですが、うまくいきませんでした。最初の LinearLayout の要素しか表示されません。上記のコードで weight 属性をどのように使用すると、3 番目の R.Lay がストレッチされ、それがまさに私が回避しようとしている動作です。そして、Margin_right を負の値に設定すると、何も起こりません。

どんな考えやアイデアにも感謝します。ありがとうございました!

4

1 に答える 1

0

私にとってはうまくいく次の解決策を見つけました。

<LinearLayout
    android:id="@+id/mainLinearLayout"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:baselineAligned="false"
    android:clipChildren="false"
    android:weightSum="100" >

    <RelativeLayout
        android:id="@+id/invisbleRelativeLayout"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="32"
        android:background="#0000" >
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/placeholder1"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="43"
        android:background="#F0FFFF" >
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/placeholder2"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="43"
        android:background="#F0FFFF" >
    </RelativeLayout>
</LinearLayout>

3 つのレイアウトの重みの合計が、一番上の LinearLayout の 100 より大きいことに注意してください。

于 2012-09-17T14:00:34.983 に答える