ListView不滚动

时间:2014-04-30 10:19:48

标签: android android-listview

我在AbsoluteLayout中有一个listview,而不是滚动。

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>

和适配器代码:

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

3 个答案:

答案 0 :(得分:1)

您需要使用线性布局而不是绝对布局。此外,编辑列表视图属性,并使用以下内容:

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

答案 1 :(得分:1)

Hey AbsoluteLayout已弃用。使用LineaLayout或RelativeLayout很好。 您可以浏览this以获取更多信息。 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>

我想在你的情况下你已经给你的列表一个特定的高度,我猜这就是为什么它不滚动。 我希望这会有所帮助。

答案 2 :(得分:0)

使用RelativeLayout代替AbsoluteLayout。 API级别3中的AbsoluteLayoutdeprectatedhttp://developer.android.com/reference/android/widget/AbsoluteLayout.html