how resize Android ListView row height
Asked Answered
S

4

5

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?

Supposition answered 22/5, 2014 at 15:25 Comment(2)
Try it by giving height to textview in row_layout.Pour
richwebmobile.blogspot.com/2012/09/…Pour
S
1

The problem was background image size. android:background="@drawable/list_style" I use image from background. so i changed size of image. thanks.

Supposition answered 23/5, 2014 at 6:59 Comment(0)
S
5

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.

Springs answered 22/5, 2014 at 15:35 Comment(0)
B
3

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"
Belldame answered 22/5, 2014 at 16:6 Comment(0)
S
1

The problem was background image size. android:background="@drawable/list_style" I use image from background. so i changed size of image. thanks.

Supposition answered 23/5, 2014 at 6:59 Comment(0)
S
0

If rows are bigger than expected, that could be due to android:minWidth and android:minHeight. Try to remove those atributes.

I see that you are setting units in px. It is not recomended to do such a thing. You should use dp instead of px, except for text size. For text size it is recommended to use sp.

Without a screenshot this is all I got. Let me know if this helps.

Sandysandye answered 22/5, 2014 at 15:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.