2

this is the image of my current gridview:

enter image description here

this is what I want to get : enter image description here

This is my griview layout :

    <GridView
    android:id="@+id/gridView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    android:columnWidth="100dp"
    android:drawSelectorOnTop="true"
    android:gravity="center"
    android:numColumns="2"
    android:stretchMode="spacingWidthUniform"
    android:verticalSpacing="5dp" >
</GridView>

this is my custom row :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical"
 >

<ImageView
    android:id="@+id/image"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="fitCenter" >
</ImageView>

<TextView
    android:id="@+id/text"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp"
    android:gravity="center"
    android:includeFontPadding="false"
    android:singleLine="true"
    android:lineSpacingExtra="5dp"
    android:textSize="12sp" >
</TextView>

i've tried about 3 hours ,I couldn't and the above code is my latest code. Could you help me ? How can I make 2 rows to fill width ?

thanks

mahdi yamani
  • 923
  • 3
  • 12
  • 29
  • Please look at [Gridview with two columns and auto resized images](http://stackoverflow.com/questions/15261088/gridview-with-two-columns-and-auto-resized-images) – Smeet Dec 24 '15 at 17:50

2 Answers2

0

You need to change the ImageView layout_width + layout_height from match_parent to a fixed size with dp . For example do something like 60dp for width and height

Ido Magor
  • 544
  • 1
  • 5
  • 14
-1

You have to use an Adapter between your data (Images & Texts) and your view (GridView): Adapter

You have a good example here of a CustomGrid extending BaseAdapter : Android Custom GridView with Images and Text

Hope it helps!

Lionel

Community
  • 1
  • 1
Lionel T.
  • 1,194
  • 1
  • 13
  • 17