Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set ListView item height

I have a ListActivity which i want to change Item height refer to device height

public class MainActivity extends ListActivity
{
            .
            .
            .
            setListAdapter(new ArrayAdapter<String>(MainActivity.this,
                android.R.layout.simple_list_item_1,mainMenuItems));
}

its my ListActivity on galaxy nexus S :

enter image description here

and on galaxy nexus 7 : enter image description here

how should I define listview items height ???

like image 219
Erfan Bagheri Avatar asked Apr 19 '13 10:04

Erfan Bagheri


People also ask

How to set ListView row height?

The default line height of a ListView (in report view mode) is computed based on the control's font size. So to select the line height, choose a font with the right height in the ListView properties. For example, select MS Sans Serif 18.

How to change ListView row height in android?

Just adding to the previous answers, you can remove android:minWidth and android:minHeight to allow the row wrap the text or you can set the height you want. Android has a default value for list item height.


1 Answers

The ListView items height are the height of item layout contents, eg android.R.layout.simple_list_item_1 height. If you want different height, create an xml file and put a android:layout_height or android:minHeight attribute.

This is a modified simple_list_item_1 which refers to your value

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceListItemSmall"
    android:gravity="center_vertical"
    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
    android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
    android:paddingRight="?android:attr/listPreferredItemPaddingRight"
    android:minHeight="@dimen/your_defined_minumum_height"/>

and in your dimen.xml

<dimen name="your_defined_minumum_height">48dp</dimen>
like image 160
Yaroslav Mytkalyk Avatar answered Sep 23 '22 17:09

Yaroslav Mytkalyk