2

私は3つのボタンを並べて配置しようとしています。左側のボタンと右側のボタンは小さいボタンで、中央のボタンは残りの幅(2x2dp(=マージン))を埋める必要があります。
私は以下をコーディングしましたが、それは私の右ボタンを画面から押し続けます、これを解決する方法についてのアイデアはありますか?左のものと右のものを特権化する方法があるかもしれませんか?

<RelativeLayout
            android:id="@+id/rl"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="10dp" >

            <Button
                android:id="@+id/bPreviousQuestion"
                android:layout_width="42dp"
                android:layout_height="42dp"
                android:background="#c8c8c8"
                android:text="&lt;"
                android:textColor="#ffffff"
                android:textSize="20dp"
                />

            <Button
                android:id="@+id/bBack"
                android:layout_width="fill_parent"
                android:layout_height="42dp"
                android:layout_toRightOf="@+id/bPreviousQuestion"
                android:background="#c8c8c8"
                android:text="Go Back"
                android:textColor="#ffffff"
                android:textSize="20dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"  />

            <Button
                android:id="@+id/bNextQuestion"
                android:layout_width="42dp"
                android:layout_height="42dp"
                android:layout_toRightOf="@+id/bBack"
                android:background="#c8c8c8"
                android:text="&gt;"
                android:textColor="#ffffff"
                android:textSize="20dp" />
        </RelativeLayout>
4

5 に答える 5

3

追加してみてください:

android:layout_toLeftOf="@+id/bNextQuestion"

「戻る」ボタンに。「次へ」で次の行を削除します。

android:layout_toRightOf="@+id/bBack"

そして追加:

android:layout_alignParentRight="true"
于 2012-11-30T17:30:14.770 に答える
2

これを試して:

{Previous} を 42 dp 幅で左揃えの親に設定します。

{Next} を 42 dp 幅で親を右揃えに設定します。

{Back} を Prev の右側、Next の左側に fill_parent 幅で設定します。

レイアウトを正しく理解している場合、これはボタンの間を戻るボタンで埋める必要があります。

于 2012-11-30T17:29:08.327 に答える
1

LinearLayoutの代わりに使用RelativeLayout

<LinearLayout
    android:id="@+id/rl"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="10dp"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/bPreviousQuestion"
        android:layout_width="42dp"
        android:layout_height="42dp"
        android:background="#c8c8c8"
        android:text="&lt;"
        android:textColor="#ffffff"
        android:textSize="20dp" />

    <Button
        android:id="@+id/bBack"
        android:layout_width="fill_parent"
        android:layout_height="42dp"
        android:layout_marginLeft="2dp"
        android:layout_marginRight="2dp"
        android:layout_weight="1"
        android:background="#c8c8c8"
        android:text="Go Back"
        android:textColor="#ffffff"
        android:textSize="20dp" />

    <Button
        android:id="@+id/bNextQuestion"
        android:layout_width="42dp"
        android:layout_height="42dp"
        android:background="#c8c8c8"
        android:text=">"
        android:textColor="#ffffff"
        android:textSize="20dp" />
</LinearLayout>
于 2012-11-30T17:29:48.393 に答える
0

2番目のボタンのlayout_widthは「fill_parent」です

于 2012-11-30T17:28:27.267 に答える
0

中央のボタンである 2 番目のボタンには、android:layout_width="fill_parent" を使用しています。android:layout_width="42dp" を使用する代わりに、3 番目のものが表示されます。

于 2012-11-30T17:29:25.763 に答える