简体   繁体   中英

Android ListView inside Fragment gets cut off

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 ?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM