0

I have a GridView. Each cell has an ImageView and TextViews under the image. My problem is, that when there are items with different number of lines in textview, the possitions of cells are corrupted during scrolling up.

Here is a picture, where you can see it better: http://postimg.org/image/7ajl6lbv5/

My question is: How to set fixed height to all cells in row according to the cell with the highest height.

Here are my layouts:

<GridView
    android:id="@+id/gvProducts"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:numColumns="auto_fit"
    android:verticalSpacing="8dp"
    android:horizontalSpacing="8dp"
    />

and GridItem:

<?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:background="@drawable/action_bar_item_background"
    >

<ImageView
    android:id="@+id/ivThumb"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:adjustViewBounds="true"
    />
<LinearLayout
    android:id="@+id/llDesc"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:paddingTop="8dp"
    android:paddingBottom="8dp"
    >

    <LinearLayout
        android:id="@+id/llProductGridDesc"
        android:orientation="horizontal"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:maxLines="4"
         >
        <TextView 
            android:id="@+id/tvProductName"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:textSize="14sp"
            />
    </LinearLayout>

    <LinearLayout 
        android:id="@+id/llProducPrice"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
        <TextView
            android:id="@+id/tvProductPriceDiscount"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:textSize="14sp"
            android:textStyle="bold"
            android:paddingRight="4dp"
            />
        <TextView
            android:id="@+id/tvProductPrice"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:textSize="14sp"
            android:textStyle="bold"
             />
    </LinearLayout>
 </LinearLayout>  
</LinearLayout>
Daniel
  • 31
  • 1
  • 4
  • you might want to simply limit your text size. TextView's ellipsize method might work well for you – Martin Dec 12 '14 at 21:10
  • Thank you, but it is not possible to limit text size. Sometimes there can by just one line of text and sometimes 4 lines. And I need to show them all and right under that line show another TextView. When I set android:lines="4" for the tvProductName it works. But there is lot of free space when the text is just in one line and that looks wierd. – Daniel Dec 12 '14 at 21:27
  • looks like you've got "maxLines" on a LinearLayout, i dont think thats what you want. Also dont think that LinearLayout is necessary. – browep Dec 12 '14 at 22:39
  • Yeah. The maxLines should not be there. It is just a garbage from my previous tests and after deleting it is still the same. The LinearLayout is not necessary, but in fact there were TextView and ImageView in this LL before. But the problem is still the same. – Daniel Dec 12 '14 at 22:53
  • See http://stackoverflow.com/questions/7545915/gridview-rows-overlapping-how-to-make-row-height-fit-the-tallest-item – mpkuth Dec 13 '14 at 04:06

0 Answers0