简体   繁体   English

ListView不滚动

[英]ListView is not scrolling

I have a listview inside an AbsoluteLayout , and is not scrolling. 我在AbsoluteLayout中有一个listview,而不是滚动。

the XML is : XML是:

<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. 嘿AbsoluteLayout已被弃用。 Its good to use either LineaLayout or RelativeLayout. 使用LineaLayout或RelativeLayout很好。 You can go through this 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. android:layout_height="0dp"android:layout_weight="1"将占用空间并在该列表中添加一些元素。它将滚动。

<?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 . 使用RelativeLayout而不是AbsoluteLayout The AbsoluteLayout was deprectated in API level 3: http://developer.android.com/reference/android/widget/AbsoluteLayout.html AbsoluteLayout在API级别3中进行了deprectatedhttp//developer.android.com/reference/android/widget/AbsoluteLayout.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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