Reputation: 2595
I have a fixed size 2x3 grid, a total of 6 items. Is there any way i can fit the gridview items to fill the screen ? and, is gridview a good choice in this case ? or should i use something else ?
Upvotes: 2
Views: 1979
Reputation: 1786
If you already know that you have 6 items, why not just create 6 blocks. i.e. If you have 6 images, why not just create 6 image views?
Ex:
<?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>
Upvotes: 1
Reputation: 29416
If your GridView
will always be of fixed size and you need to fit all items on the screen simultaneously (so you don't need scrolling capabilities) I suggest you use GridLayout instead. It'll be easy to fit the whole GridLayout inside the screen, by setting its layout_width
and layout_height
properties to the match_parent
.
Upvotes: 2