I want to stretch my GridView
, which contains an ImageView
and a TextView
inside each grid, to cover the complete screen of a phone.
I have already tried lots of solutions given online, but none of them worked for me. Some of the answers which I have already tried are:
How can I force a GridView to use the whole screen (regardless of display size)?
android How to stretch rows in the gridview to fill screen?
Here is my code:
activity_layout.xml
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/gaming">
<GridView
android:id="@+id/categoryGridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:verticalSpacing="1dp"
android:horizontalSpacing="1dp"
android:background="@android:color/transparent"
android:numColumns="2"
android:stretchMode="columnWidth"
android:layout_weight="1" />
</FrameLayout>
category_grid_single.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativelayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/gridImageView"
android:layout_width="60dip"
android:layout_height="60dip"
android:scaleType="centerCrop"
android:gravity="center"
android:layout_centerInParent="true"
android:layout_margin="1dp"/>
<TextView
android:id="@+id/gridImageViewText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/gridImageView"
android:layout_margin="5dp"
android:gravity="center"
android:textSize="20sp"
android:textStyle="bold"
android:layout_centerHorizontal="true"
android:textColor="@color/colorWhite" />
</RelativeLayout>
CustomAdapter.java
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View grid;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
grid = inflater.inflate(R.layout.main_category_grid_single, null);
grid.setMinimumHeight(mheight/3);//mheight is the Height of the screen
} else {
grid = convertView;
}
TextView textView = (TextView) grid.findViewById(R.id.gridImageViewText);
ImageView imageView = (ImageView)grid.findViewById(R.id.gridImageView);
textView.setText(category[position]);
imageView.setImageResource(ImageId[position]);
return grid;
}
I am trying to achieve a GridView
similar to below Image. But currently after setting up my GridView
I am getting empty space in the bottom. If there is any better way to achieve it other than the GridView
then please suggest that too.
This is what I am getting
Any Help will be appreciated. Thanks in advance!