0

画面にボタンを配置しようとしています。この画面を画面全体の同じスペースに分割したい。Android:layout_weight での使用に関する多くの回答を読みましたが、成功しませんでした。

コード:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

<Button
    android:id="@+id/p_data_button"
    android:layout_width="wrap_content"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:layout_gravity="center"
    android:background="@drawable/p_selector"
    />
<Button
    android:id="@+id/p1_data_button"
    android:layout_width="wrap_content"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:layout_gravity="center"
    android:background="@drawable/p1_selector"
    />
<Button
    android:id="@+id/p2_data_button"
    android:layout_width="wrap_content"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:layout_gravity="center"
    android:background="@drawable/p2_selector"
    />
<Button
    android:id="@+id/p3_data_button"
    android:layout_width="wrap_content"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:layout_gravity="center"
    android:background="@drawable/p3_selector"/>

</LinearLayout>

編集:

この背景はセレクターで動作します。それは影響を受けていますか?

回答を追加します。

4

5 に答える 5

0

ウェイトを使用android:layout_height="match_parent"していて、要素がスペース全体を覆うようにしたい場合に使用します。

于 2013-05-27T12:24:34.967 に答える
0

ボタンのサイズは「wrap_content」です。それらは表示されていません。

android:text="test"すべてのボタンにテキストを配置する だけです。それはうまくいくでしょうそれ以外の場合は、背景セレクターで画像を使用します。

于 2013-05-27T12:34:47.250 に答える