我有一个固定大小的2x3网格,共有6个项目。有什么办法可以让gridview项目填满屏幕吗? 并且,在这种情况下,gridview是一个不错的选择吗?或者我应该使用其他东西吗?
答案 0 :(得分:1)
如果你已经知道你有6个项目,为什么不创建6个块。即如果你有6张图片,为什么不创建6张图片?
例如:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="3" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:orientation = "horizontal"
android:layout_weight="1"
android:weightSum="100">
<ImageView
android:id="@+id/image1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="50"
android:src="@drawable/sunny"/>
<ImageView
android:id="@+id/image2"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="50"
android:src="@drawable/sunny"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:orientation = "horizontal"
android:layout_weight="1"
android:weightSum="100">
<ImageView
android:id="@+id/image3"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="50"
android:src="@drawable/sunny"/>
<ImageView
android:id="@+id/image4"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="50"
android:src="@drawable/sunny"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:orientation = "horizontal"
android:layout_weight="1"
android:weightSum="100">
<ImageView
android:id="@+id/image5"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="50"
android:src="@drawable/sunny"/>
<ImageView
android:id="@+id/image6"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="50"
android:src="@drawable/sunny"/>
</LinearLayout>
</LinearLayout>
答案 1 :(得分:1)
如果您的GridView
始终具有固定大小,并且您需要同时在屏幕上显示所有项目(因此您不需要滚动功能),我建议您改用GridLayout。通过将layout_width
和layout_height
属性设置为match_parent
,可以轻松地将整个GridLayout放入屏幕内。