简体   繁体   中英

Android: Can't get scroll a scrollview

i'm pretty new in use of shinobi chart. Currently i'm try to design a layout that contains a chart. The layout contains serveral other elements and so i added a scrollview to manage all correctly.... but the scroll seems not working... my layout file is

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

    <LinearLayout
        android:id="@+id/box_title_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/box_title_view"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Titolo" />

        <ImageButton
            android:id="@+id/box_title_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/dettaglio" />

    </LinearLayout>
    <ScrollView
        android:id="@+id/fragment_detaill_scroll_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true" >

        <LinearLayout
            android:id="@+id/box_body_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <LinearLayout
                android:id="@+id/chart_container"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical" >

                <fragment
                    android:id="@+id/chart_fragment"
                    android:name="com.shinobicontrols.charts.ChartFragment"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>

            </LinearLayout>

            <LinearLayout
                android:id="@+id/chart_controls"
                android:layout_width="match_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical" >

                <ListView
                    android:id="@+id/lvImageList"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" >
                </ListView>

            </LinearLayout>

        </LinearLayout>
    </ScrollView>
</LinearLayout>

The effect is all is visible until the chart, which is visible itself but the listview under the chart no. I tried to scroll down but i can't get it working. Currently i'm developing using a Nexus 7. Someone can help me?

EDIT: The problem is than the ScrollView doesn't scroll! No the ListView. If i remove the ListView and something else the ScrollView still no scrolls!

You shouldn't put a ListView inside a ScrollView because the ListView class implements its own scrolling and it just doesn't receive gestures because they all are handled by the parent ScrollView. But I found a solution that works for me and can scroll the ListView without problems.

ListView listView = (ListView)findViewById(R.id.lvImageList); 
listView .setOnTouchListener(new ListView.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
    int action = event.getAction();

        switch (action) {
            case MotionEvent.ACTION_DOWN:
                // Disallow ScrollView to intercept touch events.
                v.getParent().requestDisallowInterceptTouchEvent(true);
                break;

            case MotionEvent.ACTION_UP:
                // Allow ScrollView to intercept touch events.
                v.getParent().requestDisallowInterceptTouchEvent(false);
                break;
        }

        v.onTouchEvent(event);
        return true;
}
});

Here TouchEvent on Parent View ie ScrollView will disable and receive gestures to the Child View ie ListView.

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