按钮的大小和位置

时间:2013-12-30 11:39:49

标签: android button user-interface position screen

我正在为计算器设计一个简单的UI:一些按钮和一个用于输入/输出视图的文本字段。我使用相对布局(为了将按钮放在布局的底部),但它们并不占用整个屏幕,所以对于大屏幕的设备,按钮非常小。如果我使用线性布局,我可以占据所有空间,但我不能把它们放在他们的位置。

有什么建议吗?

非常感谢。

1 个答案:

答案 0 :(得分:1)

您可以使用具有LinearLayout属性的多个weightSum组件。我们假设您有1-9个数字可供开始使用。

7 8 9
4 5 6
1 2 3

根布局将是LinearLayout

的垂直weightSum="3"

在包含LinearLayoutweightSum="3"的三个横向layout_weight="1"内,所有Button都有layout_weight="1"

一些xml让你入门:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="3" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:paddingBottom="1dp"
        android:weightSum="3" >

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1" >
        </Button>

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1" >
        </Button>

        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1" >
        </Button>
    </LinearLayout>
etc..