Android - 如何使用此结构显示六个按钮?

时间:2016-01-02 19:15:29

标签: android

我想使用以下结构在XML中显示六个按钮:

enter image description here

我已经尝试过这样做,但它并不适用于所有屏幕尺寸。我想绘制一个适用于所有屏幕尺寸的结构,你能帮助我吗?

1 个答案:

答案 0 :(得分:1)

我已使用线性布局回答了您的查询。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:weightSum="10"
android:orientation="vertical"
android:layout_height="match_parent"
tools:context=".ActivityState">
<LinearLayout
    android:layout_weight="6"
    android:layout_width="match_parent"
    android:layout_height="0dp">
<LinearLayout
android:orientation="horizontal"
android:weightSum="2"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
    android:layout_weight="1"
    android:layout_width="0dp"
    android:layout_height="match_parent">
    <Button android:text="Button"
        android:layout_weight="1"
        android:layout_width="wrap_content"

        android:layout_height="match_parent" />

</LinearLayout>

<LinearLayout
    android:weightSum="2"
    android:layout_width="0dp"
    android:layout_weight="1"
    android:orientation="vertical"
    android:layout_height="match_parent">

    <Button android:text="Button"
        android:layout_weight="1"
        android:layout_width="match_parent"

        android:layout_height="0dp" />

    <Button android:text="Button"
        android:layout_weight="1"
        android:layout_width="match_parent"

        android:layout_height="0dp" />
</LinearLayout>


</LinearLayout>
</LinearLayout>

<LinearLayout
    android:layout_weight="2"
    android:layout_width="match_parent"
    android:layout_height="0dp">

    <Button android:text="Button"
        android:layout_weight="1"
        android:layout_width="match_parent"

        android:layout_height="match_parent" />
</LinearLayout>

<LinearLayout
    android:layout_weight="2"
    android:layout_width="match_parent"
    android:layout_height="0dp">

    <Button android:text="Button"
        android:layout_weight="1"
        android:layout_width="0dp"

        android:layout_height="match_parent" />

    <Button android:text="Button"
        android:layout_weight="1"
        android:layout_width="0dp"

        android:layout_height="match_parent" />
</LinearLayout>

</LinearLayout>

希望这有帮助! :)