1

以下は、すべてのボタンビューを整列させようとしている簡単なコードです

  • 図のように、すべてのボタンが等間隔になるようにする方法。
  • 私もランダムなテキストサイズで試してみましたが、うまくいきません:(

何か案は

私が試したこと::

<TableRow
            android:id="@+id/tableRow5"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="2sp" >

            <RelativeLayout
                android:id="@+id/BottomNavigationBarCopperChimneyDesc"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <Button
                    android:id="@+id/CopperChimneyDescriptionButton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:text="Description"
                    android:textSize="14dp" />

                <Button
                    android:id="@+id/CopperChimneyLocationButton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_toRightOf="@+id/CopperChimneyDescriptionButton"
                    android:text="Location"
                    android:textSize="14dp" />

                <Button
                    android:id="@+id/CopperChimneyPhotosButton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_toLeftOf="@+id/CopperChimneyFriendsButton"
                    android:text="Photos"
                    android:textSize="14dp" />

                <Button
                    android:id="@+id/CopperChimneyFriendsButton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:text="Friends"
                    android:textSize="15dp" />
            </RelativeLayout>
        </TableRow>

図


4

2 に答える 2

0

代替アプローチは、時々役立つかもしれません。LinearLayout と weights を使用したソリューションは正常に機能しますが、パフォーマンスの問題のために、簡単に回避できる余分なレイアウトの膨張は好きではありません。

1. dimens.xml でボタンの幅を定義します。Android スマートフォンの画面幅は 320 または 360 dp です。

値/dimen.xml

<dimen name="button_width">80dp</dimen>

values-sw360dp/dimen.xml (これらのリソースは 360dp 幅以上の画面に使用されます)

<dimen name="button_width">90dp</dimen>

もちろん、タブレットのサポートが必要な場合は、追加の dimens.xml を定義する必要があります。

2. ボタンには次の値を使用します。

android:layout_width="@dimen/button_width"
于 2013-08-11T08:16:46.630 に答える
0

同じサイズが必要な場合は、 LineaLayout を使用する必要があります。RelativeLayout 内に配置するだけです。また、ボタンの重みを均等にする必要があります。ここのように:等しいボタン

于 2013-08-11T08:07:33.267 に答える