簡體   English   中英

Android:如何更改將屏幕分成3個相等的按鈕

[英]Android: How to change divide the screen in 3 equal buttons

我在布局中有3個按鈕。 我想要做的是增加按鈕的大小,以便它們覆蓋整個屏幕。 如何在xml文件中執行此操作?

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="3">

<Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="New Button"
    android:id="@+id/button"
    android:layout_weight="1"/>

<Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="New Button"
    android:id="@+id/button2"
    android:layout_weight="1"/>

<Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="New Button"
    android:id="@+id/button3"
    android:layout_weight="1"/>
</LinearLayout>

您需要體重

您可以使用LinearLayoutweight屬性。 我要猜測一下,並假設您想要垂直布局的按鈕。

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

    <Button
        android:id="@+id/button_1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/button_2"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"/>

    <Button
        android:id="@+id/button_3"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"/>

</LinearLayout>

Buttons將始終充滿屏幕,您可以使用體重值來修改其高度

您需要將按鈕放在LinearLayout內並使用權重:

<LinearLayout 
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" 
android:weightSum="3">
<Button 
    android:layout_height="0dip"
    android:layout_width="wrap_content"
    android:layout_weight="1"
    />
<Button 
    android:layout_height="0dip"
    android:layout_width="wrap_content"
    android:layout_weight="1"
    />
<Button 
     android:layout_height="0dip"
    android:layout_width="wrap_content"
    android:layout_weight="1"
    />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM