0

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!

tassadar
  • 35
  • 1
  • 9
  • you can't use listview inside scrollview. – Shashank singh Mar 11 '16 at 11:21
  • Check this answer [Using a ListView to make it not scroll is extremely expensive and goes against the whole purpose of ListView. You should NOT do this. Just use a LinearLayout instead.](http://stackoverflow.com/questions/3495890/how-can-i-put-a-listview-into-a-scrollview-without-it-collapsing?rq=1) – Shashank singh Mar 11 '16 at 11:28

1 Answers1

1

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 i.e ScrollView will disable and receive gestures to the Child View i.e ListView.

  • Yes i know but my problem is that the parent ScrollView doesn't scroll! I expected that it does, since the bottom listview is outside of the screen.... but no scroll! – tassadar Mar 11 '16 at 13:11