1

OK、これは何年もの間悩まされてきた問題です。Android画面の上部に5つのボタンを横一列に配置しようとしています。これらのボタンはすべて、画面の幅の 20% の幅である必要があります (すべてのボタンが隙間なく並んで収まるように)。

私はXMLを理解できません。これどうやってするの?アイデア/サンプルはありますか? ありがとう!

4

2 に答える 2

4

ボタン行には、画面の全幅の水平線形レイアウトを使用し、その中にすべてのボタンを配置し、ボタンのレイアウト幅を 0 に設定し、レイアウト ウェイト > 0 に等しくします。

<LinearLayout
     . . .
     android:layout_width="match_parent"
     android:orientation="horizontal"
     />

     <Button
         . . .
         android:layout_width="0"
         android:layout_weight="1"
         />

     <Button
         . . .
         android:layout_width="0"
         android:layout_weight="1"
         />

     . . .
</LinearLayout>
于 2012-07-18T17:40:46.010 に答える
3
<LinearLayout
    ...
    layout_width = "match_parent"
    layout_height = "wrap_content" />

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

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

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

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

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

</LinearLayout>
于 2012-07-18T17:41:10.097 に答える