5

5つのボタンが含まれるフラグメントに取り組んでいます。タブレットのような大画面では、5つのボタンすべてを上部に配置するフラグメントを使用します。すべてのlayout_widthを1に設定しましたが、ボタンが画面全体に均等に広がっていません。

期待される[すべて][私の][ボタン][行く][ここ]

取得するものb1b2b3 b4 b5 b3とb5は1つのボタンです...表示するだけで、1つの単語[all] [my] [but][go][her]が壊れて1行下になります。[トン][e]

私はそれで遊んでいて、さまざまなことを試みてきましたが、それを変えることはできません。どんな助けでも大歓迎です。ありがとうございました。

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/xlarge_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<Button
    android:id="@+id/tip_btn"
    android:layout_width="0px"
    android:layout_height="wrap_content"
    android:layout_weight="2"
    android:text="@string/tip_button"
    android:onClick="tipButton">
</Button>

<Button
    android:id="@+id/preference"
    android:layout_width="0px"
    android:layout_height="wrap_content"
    android:layout_weight="2"
    android:text="@string/settings"
    android:onClick="showPreferences">
</Button>

<Button
    android:id="@+id/rate_btn"
    android:layout_width="0px"
    android:layout_height="wrap_content"
    android:layout_weight="2"
    android:text="@string/rate_button"
    android:onClick="rateButton">
</Button>

<Button
    android:id="@+id/feedback_btn"
    android:layout_width="0px"
    android:layout_height="wrap_content"
    android:layout_weight="2"
    android:text="@string/feedback_button"
    android:onClick="feedbackButton">
</Button>

<Button
    android:id="@+id/cancel_btn"
    android:layout_width="0px"
    android:layout_height="wrap_content"
    android:layout_weight="2"
    android:text="@string/exit_button"
    android:onClick="cancelButton">
</Button>
</LinearLayout>
4

2 に答える 2

27

簡単な答え:ボタンのlayout_widthを0に設定します。layout_weightは、レイアウト内の要素間に残ったスペースをどのように広げるかを決定するために使用されます。したがって、幅をゼロに設定しない場合、ボタンのコンテンツのサイズがボタンの大きさに影響します。

ウェイトがどのように機能するかを説明する2つの優れたブログ投稿を次に示します。

http://blog.stylingandroid.com/archives/297 http://blog.stylingandroid.com/archives/312

于 2012-07-20T18:47:55.563 に答える
8

layout_weightを使用しているため、layout_widthに0dpを指定する必要があります。動作するはずです。

于 2014-06-27T15:36:11.000 に答える