在Android中静态创建2X2图像视图的gridview
我正在尝试创建一个视图,该视图将在2x2格式中包含4个imageView。这就是我的想法:在Android中静态创建2X2图像视图的gridview,android,gridview,imageview,Android,Gridview,Imageview,我正在尝试创建一个视图,该视图将在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
<?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>
我得到这个错误:
Binary XML file line #2: Error inflating class GridLayout
有人知道为什么会这样吗?我试图按照上的说明操作,但没有多大帮助第5行的XML文件中有一个错误
android:layout_height="match_parent""
属性值以
“
结尾,而不是以”
结尾。第5行的XML文件中存在错误
android:layout_height="match_parent""
属性值以
“
结尾,而不是”
本应使用网格视图,但实际使用的是网格布局。
请尝试以下博文:
顺便问一下,您的
R.id.grid\u视图在哪里?我在您的xml中没有看到任何类似grid_view的名称。您应该使用grid view,但是您使用的是GridLayout。
请尝试以下博文:
顺便问一下,您的R.id.grid\u视图在哪里?我在您的xml中没有看到任何类似grid_view的名称。是的,只是一个小的输入错误。当然,这并不是导致错误的原因。我修好了it@Md.AbdulMunim我修正了别人告诉我的双精度“”,而不是我在这个问题上所问的错误:)是的,只是一个小的打字错误。当然,这并不是导致错误的原因。我修好了it@Md.AbdulMunim我修复了告诉我的双精度“”,而不是我在这个问题中所问的错误:)grid_view是xml文件的名称。这篇博文谈到了动态使用网格,而我希望它是静态的,就像你不能像这样加载xml文件一样。您只能以这种方式加载xml中的特定组件。尝试此操作-setContentView(R.layout.gridLayout1)
这应该会对网格进行充气,因为视图充气器.grid\u视图是xml文件的名称。这篇博文谈到了动态使用网格,而我希望它是静态的,就像你不能像这样加载xml文件一样。您只能以这种方式加载xml中的特定组件。尝试此操作-setContentView(R.layout.gridLayout1)
这将在视图充气时充气网格。