0

私はマスター/詳細アプリで作業しており、私の activity_twopane には詳細ペインの下部にボタン バー (配置したい) があります。破片のディテールの下に配置できますが、どうしても下に揃えることができません。
を使用してシングルペインモードで正常に動作していますandroid:layout_weight="1"が、ネストされたウェイトを使用するという警告があっても、2 ペインモードでは動作しません。
これは今のようです:
現在のレイアウト
そして、これは私がこれまでに得たレイアウト xml です:

<LinearLayout 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:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    android:baselineAligned="false"
    android:divider="?android:attr/dividerHorizontal"
    android:orientation="horizontal"
    android:showDividers="middle"
    tools:context=".DocumentoListActivity" >

    <fragment
        android:id="@+id/documento_list"
        android:name="br.com.DocumentoListFragment"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        tools:layout="@android:layout/list_content" />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content" 
        android:layout_weight="3"
        android:orientation="vertical">

        <FrameLayout
            android:id="@+id/documento_detail_container"
            android:layout_width="match_parent"
            android:layout_height="fill_parent" />

        <LinearLayout
            android:id="@+id/documento_twopane_buttons"
            style="android:attr/buttonBarStyle"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/documento_twopane_buttonBaixar"
                style="?android:attr/buttonBarButtonStyle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button 1" />

            <Button
                android:id="@+id/documento_twopane_buttonAssinar"
                style="?android:attr/buttonBarButtonStyle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button 2" />
        </LinearLayout>
    </LinearLayout>

</LinearLayout>  

私のボタンバーは の中にあるのでLinearLayout、その中には使えませんRelativeLayout with android:layout_alignParentBottom="true"

質問

これは s で実行できますか、それともすべてを変更して??LinearLayoutに入れる必要がありますか?RelativeLayout

4

3 に答える 3

1

ここで使用できますRelativeLayoutが、このように使用すると、ネストされたレイアウトは大した問題ではありません。一度だけ膨らませます。詳細LinearLayoutは次のようになります。

<LinearLayout
    android:layout_width="0dp"
    android:layout_height="wrap_content" 
    android:layout_weight="3"
    android:orientation="vertical">

    <FrameLayout
        android:id="@+id/documento_detail_container"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:weight="1" />

    <LinearLayout
        android:id="@+id/documento_twopane_buttons"
        style="android:attr/buttonBarStyle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/documento_twopane_buttonBaixar"
            style="?android:attr/buttonBarButtonStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button 1" />

        <Button
            android:id="@+id/documento_twopane_buttonAssinar"
            style="?android:attr/buttonBarButtonStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button 2" />
    </LinearLayout>
</LinearLayout>

ここで注意すべき重要なことはandroid:weightLinearLayout. 2 人の子がいて、メインの子の重みを 1 に設定し、対応する長さまたは幅の軸を 0 に設定するwrap_contentと、もう一方の子と一緒に使用でき、必要なだけのスペースしか占有しません。

于 2013-08-26T16:27:36.363 に答える
1

高さをmatch_parentに設定して、ボタンの線形レイアウトを別のレイアウト内にラップします

Linear レイアウト (ボタンを含む)の高さをmatch_parentに設定し、重力下に設定します

これはあなたが望むように機能します

 <LinearLayout 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:layout_marginLeft="16dp"
 android:layout_marginRight="16dp"
 android:baselineAligned="false"
 android:orientation="horizontal"
 android:showDividers="middle"
 tools:context=".DocumentoListActivity" >

<fragment
android:id="@+id/documento_list"
android:name="br.com.DocumentoListFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
tools:layout="@android:layout/list_content" />

<!-- Set this layout height to match_parent -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:orientation="vertical" >

 <!-- Set this layout height to wrap_content -->
<FrameLayout
    android:id="@+id/documento_detail_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

 <!-- Set this layout height to match_parent -->
<LinearLayout
    android:id="@+id/documento_twopane_buttons"
    style="android:attr/buttonBarStyle"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

<!-- Set this layout height to match_parent and gravity to bottom -->
<LinearLayout
    android:id="@+id/documento_twopane_buttons1"
    style="android:attr/buttonBarStyle"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:layout_gravity="bottom"
    android:baselineAligned="false"
    android:gravity="bottom"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/documento_twopane_buttonBaixar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button 1" />

    <Button
        android:id="@+id/documento_twopane_buttonAssinar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button 2" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
于 2013-08-26T16:51:07.043 に答える
0

@twnteeの回答はうまくいったように見えましたが、右側のペインのテキストが長すぎると、ボタンの上に表示されて到達できなくなりました。そのため、いくつかのスイッチを作成する必要がありました。したがって、ネストされた重みを使用する必要がありましたが、少なくともネストされたものは必要ありませんでしたLinearLayouts:

<LinearLayout 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:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    android:baselineAligned="false"
    android:orientation="horizontal"
    android:showDividers="middle"
    tools:context=".DocumentoListActivity" >

    <fragment
        android:id="@+id/documento_list"
        android:name="br.com.DocumentoListFragment"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        tools:layout="@android:layout/list_content" />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="3"
        android:orientation="vertical" >

        <FrameLayout
            android:id="@+id/documento_detail_container"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            tools:context=".DocumentoDetailActivity"
            tools:ignore="MergeRootFrame,NestedWeights" />

        <LinearLayout
            android:id="@+id/documento_twopane_buttons"
            style="android:attr/buttonBarStyle"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="bottom"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/documento_twopane_buttonOne"
                style="?android:attr/buttonBarButtonStyle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/button_one" />

            <Button
                android:id="@+id/documento_twopane_buttonTwo"
                style="?android:attr/buttonBarButtonStyle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/button_two" />
        </LinearLayout>
    </LinearLayout>

</LinearLayout>
于 2013-08-30T13:45:00.167 に答える