java - GridLayout 不会显示在网格中

标签 java android xml android-support-library android-gridlayout

我使用 gridLayout 来简单地显示 2x2 布局。我稍后会增加这个,但我只是想让一个样本起作用。截至目前,它们排成一排。通过查看我的 xml,有人会发现我做错了什么明显的事情吗?我的代码可以编译,我的 xml 可以“验证”。谢谢

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:grid="http://schemas.android.com/apk/res-auto"
    xmlns:app="http://schemas.android.com/apk/res/com.test.example"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <android.support.v7.widget.GridLayout
        android:id="@+id/GridLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:columnCount="2"
        android:rowCount="2" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
    </android.support.v7.widget.GridLayout>

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:ems="10" />

</RelativeLayout>

最佳答案

GridLayout 的文档指定,在配置 GridLayout 的子级时,您不需要使用以下任一特殊大小值:WRAP_CONTENT 或 MATCH_PARENT。摘要中指定here

关于java - GridLayout 不会显示在网格中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17535652/

相关文章:

java - 简单的 boolean 问题

java - 将上传的文件保存在特定位置

java - 同一对象的迭代器不独立运行

java - 仅转义 XML 实体一次

java - 在Java中解析包含HTML实体的XML文件而不改变XML

xml - IXMLDocument.SaveToFile() 使用制表符而不是空格进行缩进

Java泛型,嵌套类型参数

java - Android - 带箭头的水平 ListView

android - 检查 MenuItem 是否在 ActionBar 溢出

java - Pebble 表盘向 Android 应用程序发送消息