Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
具有匹配宽度和高度的Android布局视图_Android_Android Layout - Fatal编程技术网

具有匹配宽度和高度的Android布局视图

具有匹配宽度和高度的Android布局视图,android,android-layout,Android,Android Layout,我是android新手,尝试创建如下布局: ---------- | y | x| ---------- | | | | ---------- | | | ---------- 标有x的框具有相同的宽度和高度,框y具有2*x的宽度。宽度x+y是屏幕的全宽。所有3行高度相等,其中行高度与x的宽度和高度匹配。有没有一种方法可以在xml中实现这一点?我得到的最接近的是下面的xml,但行高度与框x的宽度不匹配。有什么想法吗 <LinearLayout android:

我是android新手,尝试创建如下布局:

----------
|  y  | x|
----------
|  |  |  |
----------
|     |  |
----------
标有x的框具有相同的宽度和高度,框y具有2*x的宽度。宽度x+y是屏幕的全宽。所有3行高度相等,其中行高度与x的宽度和高度匹配。有没有一种方法可以在xml中实现这一点?我得到的最接近的是下面的xml,但行高度与框x的宽度不匹配。有什么想法吗

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="horizontal">

    <TextView
        android:id="@+id/text"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="2"
        android:layout_alignParentBottom="true"
        android:background="#ffffffff"
        android:text="text is here"
        />
    <TextView
        android:id="@+id/text2"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:layout_alignParentBottom="true"
        android:background="#ffffffff"
        android:text="and text is here"
        />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/text3"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:layout_alignParentBottom="true"
            android:background="#ffffffff"
            android:text="text is here"
            />

        <TextView
            android:id="@+id/text4"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:layout_alignParentBottom="true"
            android:background="#ffffffff"
            android:text="and text is here"
            />

        <TextView
            android:id="@+id/text5"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:layout_alignParentBottom="true"
            android:background="#ffffffff"
            android:text="and text is here"
            />
    </LinearLayout>
</LinearLayout>

尝试使用GridLayou:

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:columnCount="4"
            android:orientation="horizontal">

    <Button
            android:layout_gravity="fill"
            android:layout_columnSpan="3"
            android:text="1"/>

    <Button android:text="2"/>

    <Button android:text="3"/>

    <Button android:text="4"/>

    <Button android:text="5"/>

    <Button android:text="6"/>

    <Button
            android:layout_gravity="fill"
            android:layout_columnSpan="3"
            android:text="7"/>

    <Button android:text="8"/>    

</GridLayout>

结果:


GridLayout看起来是个不错的方法。如何使其适合屏幕宽度并调整方框,使其成为正方形?我正在尝试重量和0dp宽度/高度,但不起作用。您可以通过代码或使用自定义方形视图来完成。