0

1行に3つのボタンを配置する必要があります。/LinearLayout/を使用します。問題は、ボタンのテキストを変更するときです。「android:layout_width = "wrap_content」のために幅が変更されます。タブボタンが画面幅i4:4:2の比率を占めるようにしたいのですが、「wrap_content」句はこれを破りますが、正確なサイズを使用できないためです。設計時にデバイスの画面幅を知る。

コードを使用せずにこれを解決する簡単な方法を知っている人はいますか?

4

3 に答える 3

1

幅をwrap_contentに設定しないでください。代わりに比例重みを設定します。

<LinearLayout
    ...
    layout_width = "match_parent"
    layout_height = "wrap_content" />

    <Button
        ....
        layout_width = "0dp"
        layout_height = "wrap_content"
        layout_weight = 2 />

    <Button
        ....
        layout_width = "0dp"
        layout_height = "wrap_content"
        layout_weight = 2 />

    <Button
        ....
        layout_width = "0dp"
        layout_height = "wrap_content"
        layout_weight = 1 />

</LinearLayout>
于 2012-07-19T13:24:58.843 に答える
0

以下を試してください:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:weightSum="10"   //    SEE THIS IS 4+4+2 = 10
        android:layout_centerHorizontal="true" >

        <Button
            android:layout_weight="4"   // THIS    IS   4
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />

        <Button
            android:layout_weight="4"   // THIS    IS   4
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />

        <Button
            android:layout_weight="2"   // THIS    IS   2
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />

    </LinearLayout>

</RelativeLayout>
于 2012-07-19T13:28:43.917 に答える
0

android:layout_weight="4dp" である必要があります

于 2012-07-19T13:35:47.013 に答える