开发者

ScrollView Not Responding

I have the following XML and am not doing anything fancy with overriding scrolling behaviors:

<?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"
    />
</Lin开发者_开发技巧earLayout>

However, while the embedded listview does respond to presses and long presses, it does not scroll. What am I doing wrong?

The trailing TextView is the listview's emptyview.


ScrollView does not play nicely with any other view that scrolls natively, i.e WebView, ListView, etc.

Try a Relative layout and see if this does what you need.

<?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>


In android it should not put ListView inside a ScrollView. It will not work.


Take the ListView out of the ScrollView. It causes problems, and is unnecessary (ListView handles scrolling on its own.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜