简体   繁体   中英

ListView is not scrolling

I have a listview inside an AbsoluteLayout , and is not scrolling.

the XML is :

<ListView
    android:id="@+id/listTrauma"
    android:layout_width="fill_parent"
    android:layout_height="178dp"
    android:layout_x="0dp"
     android:scrollbars="none"
    android:layout_y="666dp" >
</ListView>

and the adapter code:

adapter = new ArrayAdapter<String>(getApplicationContext(),
            R.layout.test1, dataTrauma);

You need to use linear layout instead of absolute layout. And also, edit your list view properties, and use something like this:

<ListView
android:id="@+id/listTrauma"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="none"/>

Hey AbsoluteLayout is deprecated. Its good to use either LineaLayout or RelativeLayout. You can go through for more information. 信息以获取更多信息。 android:layout_height="0dp" and android:layout_weight="1" will occupy the space and add some elements in that list.It will scroll.

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        android:id="@+id/widget0"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        xmlns:android="http://schemas.android.com/apk/res/android">

        <ListView
           android:id="@+id/listTrauma"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:scrollbars="none"
            android:layout_weight="1">
        </ListView>

    </LinearLayout>

And I guess in your case you have given a specific height to your list, I guess that's why it's not scrolling. I hope this helps.

Use the RelativeLayout instead of the AbsoluteLayout . The AbsoluteLayout was deprectated in API level 3: http://developer.android.com/reference/android/widget/AbsoluteLayout.html

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