Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GridView row height

I have a GridView that displays images, which are, unfortunately, of different sizes. They are shown in between two lines of text:

text1.1                text1.2
ImageView(IMAGE1)      ImageView(IMAGE2)
text2.1                text2.2

text3.1
ImageView(IMAGE3)
text4.1

etc....

If IMAGE1 is the same height as IMAGE2, everything is fine, but if IMAGE1 is longer than IMAGE2, text2.1 will run into text3.1 (padding doesn't seem to help much, as there's too much of it when images are of the same height).

I know there's a way to stretch the images in the ImageView so they are the same height, but is it possible to keep images as is and set the row height somehow?

like image 831
kozyr Avatar asked Mar 03 '10 23:03

kozyr


People also ask

How to set the height of GridView row in asp net?

Solution 1You can set Height in RowStyle (and AlternateRowStyle if used). If text in your row wraps, you can avoid it using cell style white-space:nowrap;overflow:hidden; . Please Sign up or sign in to vote.

How to set grid row height c#?

rowDef = new RowDefinition(); rowDef. Height = new GridLength(2, GridUnitType. Star);

How to make GridView size fixed?

You will need to make sure each table cell in the header and footer tables have fixed widths that correspond to the widths of the cells in your GridView. The GridView itself would probably be nested in a DIV tag of a fixed height.


3 Answers

You are in control over your row heights, by virtue of what you put in them. Since your cells appear to have more than one widget, they are presumably wrapped in a LinearLayout or something. Set your LinearLayouts to be some specific height, and the rows will all be that height.

Personally, I think you should be resizing your images if you are going to have text above and below each image on a per-cell basis.

like image 108
CommonsWare Avatar answered Oct 12 '22 11:10

CommonsWare


Use drawable as background on Layout that is your grid cell and define that drawable with:

<size android:height="<some height>" /> 

For example:

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"     android:shape="rectangle"> <solid android:color="#ffffff"/> <size android:height="60dip" /> </shape> 
like image 40
CloudWalker Avatar answered Oct 12 '22 13:10

CloudWalker


Here is an alternative solution that pre-measures items and sets the height of each cell to the max height in that row.

GridView rows overlapping: how to make row height fit the tallest item?

like image 45
Chase Avatar answered Oct 12 '22 12:10

Chase