1.在ScrollView里面嵌套ListView时,ListView的滑动事件无法响应。

   先看下事件分发的过程:

   由父View层的  onInterceptTouchEvent    到中间层的onInterceptTouchEvent   再到我们View层的  onTouchEvent  

   在回到中间层的  onTouchEvent  最后回到父View的onTouchEvent。

 我们在view中设置的OnTouchEvent没有响应事件,那么很清楚,在父View的OnInterceptTouchEvent 被拦截了。

 这样我们可以很明确的去重新父View的OnInterceptTouchEvent方法。

2.看下实现的效果图

 ScrollView和ListView滑动冲突问题

3.实现

  布局效果:

  

    <myapplication.com.myasynctask.entity.MyScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:fillViewport="true"
        android:layout_height="wrap_content">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <ImageView
                android:layout_height="300dp"
                android:layout_width="match_parent"
                android:src="@mipmap/background"
                android:scaleType="centerCrop"/>

            <ListView
                android:layout_height="200dp"
                android:layout_width="match_parent"
                android:id="@+id/listView"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="300dp"
                android:orientation="horizontal">
                <ImageView
                    android:layout_height="400dp"
                    android:layout_width="match_parent"
                    android:src="@drawable/zuo"/>
            </LinearLayout>

        </LinearLayout>
    </myapplication.com.myasynctask.entity.MyScrollView>
View Code

相关文章: