Android:无法滚动滚动视图

时间:2016-03-11 11:17:04

标签: android android-scrollview

我在使用shinobi图表时非常新。目前,我尝试设计包含图表的布局。布局包含其他几个元素,所以我添加了一个scrollview来正确管理....但滚动似乎不起作用...我的布局文件是

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

效果全部是可见的,直到图表,这是可见的,但是图表号下的列表视图。我试图向下滚动,但我无法正常工作。目前我正在使用Nexus 7进行开发。有人可以帮助我吗?

编辑:问题不在于ScrollView没有滚动!没有ListView。如果我删除了ListView和其他东西,ScrollView仍然没有滚动!

1 个答案:

答案 0 :(得分:1)

您不应该将ListView放在ScrollView中,因为ListView类实现了自己的滚动,它只是不接收手势,因为它们都由父ScrollView处理。 但是我找到了一个适合我的解决方案,可以毫无问题地滚动ListView。

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;
}
});

这里是父视图上的TouchEvent,即ScrollView将禁用和接收子视图的手势,即ListView。