1

I am using a ListView inside a Fragment. The items of my ListView are dynamically loaded using a Custom Adapter.

I notice that when I try to set the Font size of my items something large ( like 28dp ) , the listview will still render but will get cut off at the end so the last item will not be visible.

Here is the ListView

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:id="@+id/layoutList"
        >
        <ListView
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:id="@+id/listView"
            android:stackFromBottom="true"
        />
</LinearLayout>

and the item row

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="80dp"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:text="TextView"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="0"
        android:id="@+id/txtHours"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:textSize="28dp" />

</RelativeLayout>

is there anything wrong with my implementation ?

G-Man
  • 7,232
  • 18
  • 72
  • 100
  • 1
    Try first changing your `android:layout_height="fill_parent"` to `android:layout_height="match_parent"`, then try changing your `android:textSize=28dp` to `android:textSize=28sp`. Maybe that will have some impact on your listview. – Dusan Dimitrijevic Feb 01 '16 at 00:05

2 Answers2

1

you need to add padding and weights to your layouts. When an item of bigger size is placed in the layout the other view are over looked and hence you see the listview cuts off. Please refer to the below link : http://developer.android.com/guide/topics/ui/layout/linear.html#Weight

Hope it gives you an idea on how to design you listview layout.

Antroid
  • 391
  • 4
  • 15
-1

Set layout constraints to 0dp. That will work in most cases.

Izak
  • 909
  • 9
  • 24