Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.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_Xml - Fatal编程技术网

Android 网格布局适合全屏显示

Android 网格布局适合全屏显示,android,xml,Android,Xml,我希望我的布局像这样: 现在我使用GridLayout,这是我当前的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:o

我希望我的布局像这样:

现在我使用GridLayout,这是我当前的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="horizontal"
  xmlns:tools="http://schemas.android.com/tools"
  android:background="#000000"
 >


<GridLayout
android:id="@+id/GridLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="2"
android:fillViewport="true"
>

<!-- Button 1 -->
   <Button
    android:id="@+id/B1"
    android:layout_column="0"
    android:layout_columnSpan="2"
    android:layout_row="0"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Button 1"
    android:textColor="@android:color/white"
    android:background="@drawable/schalt2"
    />

<!-- Button 2 -->

<Button
    android:id="@+id/B2"
    android:layout_row="1"
    android:layout_column="0"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
     android:text="Button 2"
    android:textColor="@android:color/white"
    android:background="@drawable/schalt2"
    />

<Button
    android:id="@+id/B3"
    android:layout_row="2"
    android:layout_column="0"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button 3"
    android:textColor="@android:color/white"
    android:background="@drawable/schalt2"
    />

<Button
    android:id="@+id/B4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_column="1"
    android:layout_row="1"
    android:layout_columnSpan="1"
    android:layout_rowSpan="2"

    android:layout_gravity="fill_vertical"
    android:background="@drawable/schalt2"
    android:text="Button 4"
    android:textColor="@android:color/white" />

<!-- Button 5-->

<Button
    android:id="@+id/B5"
    android:layout_column="0"
    android:layout_columnSpan="2"
    android:layout_row="3"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Button 5"
    android:textColor="@android:color/white"
    android:background="@drawable/schalt2" />

<!-- Button 6 -->
<Button
    android:id="@+id/B6"
    android:layout_column="0"
    android:layout_columnSpan="2"
    android:layout_row="4"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/VIP"
    android:text="Button 6"
    android:textColor="@android:color/white"
    android:background="@drawable/schalt2"
    />

</GridLayout>
</LinearLayout>

正如你所看到的,还有很多空白:

如何使网格布局与我父母的身高相匹配

我也尝试了选项卡布局,但当达到按钮2和按钮3,按钮4,以适应2行比TayLayout来它的限制。
我现在能做什么?

使用Google
flexbox布局来实现这一点。以下是链接:-

添加
依赖项{
编译'com.google.android:flexbox:0.3.0'
}

XML:-

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.flexbox.FlexboxLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:orientation="vertical"
android:weightSum="4"
app:alignContent="stretch"
app:alignItems="stretch"
app:flexWrap="wrap">

<Button
    android:id="@+id/B1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/holo_blue_bright"
    android:text="Button 1"
    android:textColor="@android:color/white" />

<com.google.android.flexbox.FlexboxLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:flexDirection="column"
    app:layout_flexBasisPercent="50%">

    <Button
        android:id="@+id/B2"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@android:color/holo_green_dark"
        android:text="Button 2"
        android:textColor="@android:color/white"
         />

    <Button
        android:id="@+id/B3"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@android:color/holo_green_light"
        android:text="Button 3"
        android:textColor="@android:color/white"
        />

</com.google.android.flexbox.FlexboxLayout>


<Button
    android:id="@+id/B4"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/holo_orange_light"
    android:text="Button 4"
    android:textColor="@android:color/white"
    app:layout_flexBasisPercent="50%" />


<Button
    android:id="@+id/B5"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/holo_purple"
    android:text="Button 5"
    android:textColor="@android:color/white" />


<Button
    android:id="@+id/B6"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/holo_blue_dark"
    android:text="Button 6"
    android:textColor="@android:color/white" />

 </com.google.android.flexbox.FlexboxLayout>


这就是您要找的,对于我的简单案例来说似乎有点棘手。我需要一个OnClickListener来启动这些按钮和特定设计的活动您好,先生。关于这个话题我还有一个问题-也许你作为一个有经验的用户可以帮助我。