2

我正在尝试创建一个以 2x2 形式包含 4 个 imageView 的视图。这就是我的想法:

<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/gridLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:columnCount="2">

    <ImageView 
        android:id="@+id/pic1" 
        android:layout_row="0"
        android:layout_column="0"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingRight="4dip" />
    <ImageView 
        android:id="@+id/pic2" 
        android:layout_row="1"
        android:layout_column="0"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <ImageView 
        android:id="@+id/pic3" 
        android:layout_row="0"
        android:layout_column="1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
    <ImageView 
        android:id="@+id/pic4" 
        android:layout_row="1"
        android:layout_column="1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</GridLayout>

这似乎不起作用,就像我跑步时一样

setContentView(R.layout.grid_view)

我收到此错误:

Binary XML file line #2: Error inflating class GridLayout

有谁知道为什么会这样?我尝试按照http://android-developers.blogspot.co.il/2011/11/new-layout-widgets-space-and-gridlayout.html上的说明进行操作,但这并没有太大帮助

4

2 回答 2

0

您的 XML 文件第 5 行有错误

android:layout_height="match_parent""

属性值以""代替结尾"

于 2012-06-23T16:05:24.373 回答
0

您应该使用网格视图,但您使用的是 GridLayout。试试这篇博文: http ://www.java-samples.com/showtutorial.php?tutorialid=1518

顺便问一下,你在哪里R.id.grid_view?我在您的 xml 中没有看到任何类似 grid_view 的名称。

于 2012-06-23T16:11:36.827 回答