0

私は4つのボタンとして相対的なレイアウトを持っています。現在、幅に対して fill_parent を実行しています。1 番目と 4 番目のボタンについては、親を左/右に揃えることができます。ただし、すべてのボタン間に適切な間隔ができるように、ボタン 2、3 を適切に配置する方法。

プログラムでやってみましたが、ピクセル幅と dpi に基づくロジックがたくさんあるため、ボタンの正確な位置を移動または設定できません。

簡単に抜け出す方法はありますか?

4

2 に答える 2

2

最も簡単な方法は、それらを a に入れ、それぞれに andLinearLayoutを与えることですlayout_width="0dp"layout_weight="1"

于 2013-07-02T10:10:36.153 に答える
1

簡単な方法はLinearLayout、4 つのボタンを子として を使用することです。この場合、すべての子は同じ になりlayout_weightます。

android:layout_widthすべてのボタンの を「0dp」に設定することを忘れないでください。

このような:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:weightSum="4">

    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="1" />

    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="2" />

    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="3" />

    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="4" />

</LinearLayout>
于 2013-07-02T10:14:47.783 に答える