ScrollView无响应

时间:2010-12-03 04:56:09

标签: android listview scrollview

我有以下XML,并且没有对覆盖滚动行为做任何想法:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <ScrollView
        android:id="@+id/myscrollview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true"
        android:layout_weight="1">
            <ListView
                android:id="@+id/mylistview"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" />
    </ScrollView>
    <TextView 
        android:id="@+id/my_empty"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="@string/my_foo"
        android:gravity="center"
        android:visibility="gone"
    />
</LinearLayout>

但是,虽然嵌入式列表视图确实响应了按下和长按,但它不会滚动。我做错了什么?

尾随的TextView是listview的空视图。

3 个答案:

答案 0 :(得分:4)

ScrollView与其他任何本地滚动视图(即WebView,ListView等)不兼容。

尝试相对布局,看看这是否符合您的要求。

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

<ListView 
    android:id="@+id/mylistview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_alingParentTop="true"
/> 
<TextView  
    android:id="@+id/my_empty" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/my_foo" 
    android:gravity="center" 
    android:visibility="gone"
    android:layout_alignParentBottom="true"
/> 
</RelativeLayout>

答案 1 :(得分:2)

在android中它不应该将ListView放在ScrollView中。它不起作用。

答案 2 :(得分:2)

将ListView从ScrollView中取出。它会导致问题,并且是不必要的(ListView自己处理滚动。)