Reputation: 10061
I would like to create a GridView with squares items on two columns which would take the totality of the screen (match_parent).
Every item consists of an imageView and a textView.
Here is the result in image :
How do I make the items width to be equal to their variable height?
Thank you in advance!!
Upvotes: 3
Views: 4627
Reputation: 364
This is Gridview.
<GridView
android:numColumns="2"
android:id="@+id/related_contact_grid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
This is item. You will inflate this to gridview in Adapter.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/imageView"
android:text="Tendance"
android:layout_centerHorizontal="true"
</RelativeLayout>
If you want, I can support your work on this Gridview.
Upvotes: 0
Reputation: 3263
In your activity or Fragment layout you should have GridView like this:
<GridView
android:id="@+id/grid_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="2"
/>
And then you should have an Adapter that extends BaseAdapter for example and it's item should be as follow:
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawableTop="@drawable/yourDrawable"
android:layout_margin="20dip"
android:gravity="center" />
You need more explanation ?
Upvotes: 1