0

我正在使用gridLayout来简单地显示2x2布局。我会在稍后增加这个,但我只是想让样本工作。截至目前,他们排成一排。通过只看我的XML,有没有人看到任何明显的,我做错了什么?我的代码编译,我的XML“验证”。由于GridLayout将不会显示在网格中

<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> 

回答

0

我从来没有使用GridLayout前,但是从例如here,看来你需要当你想要一个新行开始到指定android:layout_column="0"属性。我建议你阅读完整的文章。

+0

嗯......不要以为这是''的用途。它们只指定一个空格,并且在editText和一个按钮之间。我从这个教程中拿出了我的例子:https://www.youtube.com/watch?v=TaCW4uL4P6c 2:54 – EGHDK

+0

“不要以为这就是''是为了”我不明白你的意思这样。 –

+0

对不起,无视。我以为我在''中只有一次出现'android:layout_column =“0”'。 – EGHDK

1

GridLayout的文档指定在配置GridLayout的子项时,不应使用以下任一特殊大小值:WRAP_CONTENT或MATCH_PARENT。在总结中指定here

+0

有意思......我删除了这些值,但现在我得到了一个关闭的力量。 – EGHDK

+0

你有什么异常? – developeralways

+0

我将它设置为0dp,现在它不强制关闭。但它没有出现。 – EGHDK