我試圖創建一個視圖,其中包括4個imageView以2x2形式。這是我腦子裏想的:在Android中靜態創建2X2圖片視圖的gridview
<?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
有誰知道爲什麼這是怎麼回事?我tryed跟隨上http://android-developers.blogspot.co.il/2011/11/new-layout-widgets-space-and-gridlayout.html指示,但它並沒有多大幫助
是的,只是一個小小的錯字。當然,這不是造成這種錯誤的原因。我修正了它 –
我看到了,我以爲你複製粘貼了你的代碼。 –
如果你已經修復它然後分享它@n00bprogrammer –