Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how resize Android ListView row height

Listview row height is too big. I designed row item so. This is ListViewItem Layout axml file

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/list_style"
    android:gravity="center_horizontal"
    android:minWidth="25px"
    android:minHeight="25px">
  <TextView
      android:text="Text"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:id="@+id/forecastName"
      android:gravity="center_vertical"
      android:padding="10px" 
      android:textColor="@color/black"/>
</LinearLayout>

and this is Listview layout

   <LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
             android:orientation="vertical"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:background="@drawable/list_style"
             android:minWidth="25px"
             android:minHeight="25px">
             <ListView
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:id="@+id/forecast"
                 android:divider="@drawable/separator"
                 android:dividerHeight="3px" />
         </LinearLayout>

When application lunches list view item has some height, it not match textview size. How can i resize row height?

like image 953
Nininea Avatar asked Jan 11 '23 13:01

Nininea


2 Answers

You can just simply provide fixed height in row layout XML:

android:layout_height="25dp"

One additional remark: Always use dp (or dip) instead of px when setting view dimensions.

like image 193
Bartosz Ostrowski Avatar answered Jan 13 '23 01:01

Bartosz Ostrowski


Just adding to the previous answers, you can remove android:minWidth and android:minHeightto allow the row wrap the text or you can set the height you want.

Android has a default value for list item height.

android:height="?android:attr/listPreferredItemHeight"
like image 28
Carlos J Avatar answered Jan 13 '23 03:01

Carlos J