├── .gitignore ├── .idea ├── codeStyles │ └── Project.xml ├── gradle.xml ├── libraries │ ├── android_arch_core_common_1_0_0_jar.xml │ ├── android_arch_lifecycle_common_1_0_0_jar.xml │ ├── android_arch_lifecycle_runtime_1_0_0.xml │ ├── com_android_support_animated_vector_drawable_26_1_0.xml │ ├── com_android_support_appcompat_v7_26_1_0.xml │ ├── com_android_support_constraint_constraint_layout_1_1_3.xml │ ├── com_android_support_constraint_constraint_layout_solver_1_1_3_jar.xml │ ├── com_android_support_design_26_1_0.xml │ ├── com_android_support_recyclerview_v7_26_1_0.xml │ ├── com_android_support_support_annotations_26_1_0_jar.xml │ ├── com_android_support_support_annotations_27_1_1_jar.xml │ ├── com_android_support_support_compat_26_1_0.xml │ ├── com_android_support_support_core_ui_26_1_0.xml │ ├── com_android_support_support_core_utils_26_1_0.xml │ ├── com_android_support_support_fragment_26_1_0.xml │ ├── com_android_support_support_media_compat_26_1_0.xml │ ├── com_android_support_support_v4_26_1_0.xml │ ├── com_android_support_support_vector_drawable_26_1_0.xml │ ├── com_android_support_test_espresso_espresso_core_3_0_2.xml │ ├── com_android_support_test_espresso_espresso_idling_resource_3_0_2.xml │ ├── com_android_support_test_monitor_1_0_2.xml │ ├── com_android_support_test_runner_1_0_2.xml │ ├── com_android_support_transition_26_1_0.xml │ ├── com_facebook_fresco_drawee_1_13_0.xml │ ├── com_facebook_fresco_fbcore_1_13_0.xml │ ├── com_facebook_fresco_fresco_1_13_0.xml │ ├── com_facebook_fresco_imagepipeline_1_13_0.xml │ ├── com_facebook_fresco_imagepipeline_base_1_13_0.xml │ ├── com_facebook_fresco_nativeimagefilters_1_13_0.xml │ ├── com_facebook_fresco_nativeimagetranscoder_1_13_0.xml │ ├── com_facebook_soloader_soloader_0_6_0.xml │ ├── com_google_code_findbugs_jsr305_2_0_1_jar.xml │ ├── com_parse_bolts_bolts_tasks_1_4_0_jar.xml │ ├── com_squareup_javawriter_2_1_1_jar.xml │ ├── javax_inject_javax_inject_1_jar.xml │ ├── junit_junit_4_12_jar.xml │ ├── net_sf_kxml_kxml2_2_3_0_jar.xml │ ├── org_hamcrest_hamcrest_core_1_3_jar.xml │ ├── org_hamcrest_hamcrest_integration_1_3_jar.xml │ └── org_hamcrest_hamcrest_library_1_3_jar.xml ├── runConfigurations.xml └── vcs.xml ├── Android_SlidingConflict.iml ├── Android_SlidingConflictDemo.iml ├── README.md ├── app ├── .gitignore ├── app.iml ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── example │ │ └── ruru │ │ └── android_slidingconflictdemo │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── ruru │ │ │ └── android_slidingconflictdemo │ │ │ ├── MainActivity.java │ │ │ ├── adapter │ │ │ ├── SubRvAdapter.java │ │ │ └── SubVpAdapter.java │ │ │ ├── data │ │ │ └── DataModel.java │ │ │ ├── differentDirection │ │ │ ├── OuterTestActivity.java │ │ │ ├── SRL_VP.java │ │ │ ├── VP_LV.java │ │ │ └── VP_SV.java │ │ │ ├── differentUI │ │ │ ├── OutSRL.java │ │ │ ├── SRL_VP_inner.java │ │ │ ├── SRL_VP_out_SRL.java │ │ │ └── SRL_VP_outer.java │ │ │ ├── fragment │ │ │ ├── AFragment.java │ │ │ ├── BFragment.java │ │ │ ├── CFragment.java │ │ │ ├── DFragment.java │ │ │ ├── EFragment.java │ │ │ ├── FFragment.java │ │ │ └── GFragment.java │ │ │ ├── sameDirection │ │ │ ├── SRL_RV.java │ │ │ ├── SRL_SV.java │ │ │ ├── SV_LV.java │ │ │ ├── SV_RV.java │ │ │ ├── SV_SV.java │ │ │ └── VP_VP.java │ │ │ ├── sameUI │ │ │ ├── SV_LV_inner.java │ │ │ ├── SV_LV_outer.java │ │ │ ├── SV_RV_inner.java │ │ │ ├── SV_RV_outer.java │ │ │ ├── SV_SV_inner.java │ │ │ ├── SV_SV_outer.java │ │ │ ├── VP_VP_inner.java │ │ │ └── VP_VP_outer.java │ │ │ └── test │ │ │ └── MethodTestActivity.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_hsv__lv.xml │ │ ├── activity_lv_vp.xml │ │ ├── activity_main.xml │ │ ├── activity_method_test.xml │ │ ├── activity_outer_test.xml │ │ ├── activity_srl_lv.xml │ │ ├── activity_srl_rv.xml │ │ ├── activity_srl_sv.xml │ │ ├── activity_srl_vp.xml │ │ ├── activity_srl_vp_old.xml │ │ ├── activity_sv_lv.xml │ │ ├── activity_sv_rv.xml │ │ ├── activity_sv_sv.xml │ │ ├── activity_sv_vp.xml │ │ ├── activity_vp_lv.xml │ │ ├── activity_vp_sv_3.xml │ │ ├── activity_vp_vp.xml │ │ ├── fragment_a.xml │ │ ├── fragment_b.xml │ │ ├── fragment_c.xml │ │ ├── fragment_d.xml │ │ ├── fragment_e.xml │ │ ├── fragment_f.xml │ │ ├── fragment_g.xml │ │ └── item.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_round.png │ │ └── timg.jpeg │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_round.png │ │ └── timg.jpeg │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_round.png │ │ └── timg.jpeg │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_round.png │ │ └── timg.jpeg │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_round.png │ │ └── timg.jpeg │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── example │ └── ruru │ └── android_slidingconflictdemo │ └── ExampleUnitTest.java ├── build.gradle ├── build └── android-profile │ ├── profile-2019-08-07-09-00-35-980.json │ ├── profile-2019-08-07-09-00-35-980.rawproto │ ├── profile-2019-08-07-09-00-39-219.json │ ├── profile-2019-08-07-09-00-39-219.rawproto │ ├── profile-2019-10-13-17-24-06-199.json │ ├── profile-2019-10-13-17-24-06-199.rawproto │ ├── profile-2019-10-13-17-24-16-216.json │ ├── profile-2019-10-13-17-24-16-216.rawproto │ ├── profile-2019-10-31-21-50-13-598.json │ ├── profile-2019-10-31-21-50-13-598.rawproto │ ├── profile-2019-10-31-21-50-19-877.json │ ├── profile-2019-10-31-21-50-19-877.rawproto │ ├── profile-2019-10-31-21-55-02-451.json │ ├── profile-2019-10-31-21-55-02-451.rawproto │ ├── profile-2019-10-31-21-55-07-560.json │ ├── profile-2019-10-31-21-55-07-560.rawproto │ ├── profile-2019-10-31-22-18-07-464.json │ ├── profile-2019-10-31-22-18-07-464.rawproto │ ├── profile-2019-10-31-22-20-17-790.json │ ├── profile-2019-10-31-22-20-17-790.rawproto │ ├── profile-2019-10-31-22-20-27-981.json │ ├── profile-2019-10-31-22-20-27-981.rawproto │ ├── profile-2019-10-31-22-25-10-371.json │ ├── profile-2019-10-31-22-25-10-371.rawproto │ ├── profile-2019-10-31-22-25-59-589.json │ ├── profile-2019-10-31-22-25-59-589.rawproto │ ├── profile-2019-10-31-22-26-10-481.json │ ├── profile-2019-10-31-22-26-10-481.rawproto │ ├── profile-2019-10-31-22-26-54-538.json │ ├── profile-2019-10-31-22-26-54-538.rawproto │ ├── profile-2019-10-31-22-34-54-896.json │ └── profile-2019-10-31-22-34-54-896.rawproto ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── local.properties └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/android_arch_core_common_1_0_0_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/android_arch_lifecycle_common_1_0_0_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/android_arch_lifecycle_runtime_1_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_animated_vector_drawable_26_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_appcompat_v7_26_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_constraint_constraint_layout_1_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_constraint_constraint_layout_solver_1_1_3_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_design_26_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_recyclerview_v7_26_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_support_annotations_26_1_0_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_support_annotations_27_1_1_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_support_compat_26_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_support_core_ui_26_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_support_core_utils_26_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_support_fragment_26_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_support_media_compat_26_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_support_v4_26_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_support_vector_drawable_26_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_test_espresso_espresso_core_3_0_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_test_espresso_espresso_idling_resource_3_0_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_test_monitor_1_0_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_test_runner_1_0_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_transition_26_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_facebook_fresco_drawee_1_13_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_facebook_fresco_fbcore_1_13_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_facebook_fresco_fresco_1_13_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_facebook_fresco_imagepipeline_1_13_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_facebook_fresco_imagepipeline_base_1_13_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_facebook_fresco_nativeimagefilters_1_13_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_facebook_fresco_nativeimagetranscoder_1_13_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_facebook_soloader_soloader_0_6_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_google_code_findbugs_jsr305_2_0_1_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/libraries/com_parse_bolts_bolts_tasks_1_4_0_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/com_squareup_javawriter_2_1_1_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/javax_inject_javax_inject_1_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/junit_junit_4_12_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/net_sf_kxml_kxml2_2_3_0_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/libraries/org_hamcrest_hamcrest_core_1_3_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/org_hamcrest_hamcrest_integration_1_3_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/org_hamcrest_hamcrest_library_1_3_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Android_SlidingConflict.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Android_SlidingConflictDemo.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android_SlidingConflictDemo 2 | ## 同方向和不同方向的Android滑动冲突解决方案 3 | 4 | ### 说明: 5 | 为了文章简洁,下面将用简写代替控件或方法全称。 6 | 7 | 总控件: 8 | * VG 代替 ViewGroup 9 | 10 | 纵向控件: 11 | * SRL 代替 SwipeRefreshLayout 12 | * TL 代替 TabLayout 13 | * SV 代替 ScrollView 14 | * RV 代替 RecyclerView 15 | * LV 代替 ListView 16 | 17 | 横向控件: 18 | * VP 代替 ViewPager 19 | * SM 代替 SlideMenu 20 | 21 | 22 | ### 事件传递: 23 | * disTE 代替 dispatchTouchEvent(事件分发) 24 | * onITE 代替 onInterceptTouchEvent(事件拦截) 25 | * onTE 代替 onTouchEvent(事件消费) 26 | * reDITE 代替 requestDisallowInterceptTouchEvent(子View要求父View不要拦截事件) 27 | * setOTL 代替 setOnTouchListener 28 | 29 |
30 | 31 | 如果大家不了解View的事件分发机制,可以参看文章: 32 | 33 | 深度理解Android事件分发机制:https://www.jianshu.com/p/80a1bb7ced57 34 | 35 | 事件冲突实际上就是对事件分发机制的应用。 36 | 37 | 38 | ### 解决事件冲突总结来看有下列几种方法: 39 | * 父View # onITE 方法:决定事件是否向子View传递。 40 | * 子View # disTE 方法:通过 reDITE 来干预父View事件的分发。 41 | * 子View # setOTL 方法:通过 reDITE 来干预父View事件的分发。 42 | * 注意:标志位在MOVE事件和DOWN事件中都会起作用。 43 | 44 | 45 | ### 滑动冲突分为三种情况: 46 | * 同方向; 47 | * 不同方向; 48 | * 同方向和不同方向混合。 49 | 50 | 51 | ### 同方向: 52 | 核心要点: 53 | * 保证外部滑动的时候只滑动外部,内部滑动的时候只滑动内部。 54 | * 点击事件交给合适的View处理。 55 | 56 | 冲突场景: 57 | * 只有一层能滑动; 58 | * 内外层同时滑动很卡顿。 59 | 60 |
61 | 62 | 1.SRL+SV/RV:没有冲突。 63 | 64 | 分析: 65 | 66 | SRL:重写了onITE方法。向下滑动,Y轴距离大于最小滑动距离,拦截事件,效果正常。 67 | 68 | SV/RV:没有重写disTE方法。向上滚动,效果正常。 69 | 70 |
71 | 72 | 2.SV+SV:有滑动冲突。 73 | 74 | 问题:内部不能滑动。 75 | 76 | 分析:外部Y轴距离大于最小滑动距离,拦截事件,导致内部不能滑动。 77 | 78 |
79 | 80 | 解决: 81 | 82 | **内部拦截:内部滑动时,执行getparent().reDITE(true);** 83 | ``` 84 | public class SV_SV_inner extends ScrollView { 85 | public SV_SV_inner(Context context) { 86 | super(context); 87 | } 88 | public SV_SV_inner(Context context, AttributeSet attrs) { 89 | super(context, attrs); 90 | } 91 | @Override 92 | public boolean dispatchTouchEvent(MotionEvent ev) { 93 | getParent().requestDisallowInterceptTouchEvent(true); 94 | return super.dispatchTouchEvent(ev); 95 | } 96 | } 97 | ``` 98 | 99 | **外部拦截:** 100 | ``` 101 | public class SV_SV_outer extends ScrollView { 102 | public SV_SV_outer(Context context) { 103 | super(context); 104 | } 105 | public SV_SV_outer(Context context, AttributeSet attrs) { 106 | super(context, attrs); 107 | } 108 | @Override 109 | public boolean onInterceptTouchEvent(MotionEvent ev) { 110 | super.onInterceptTouchEvent(ev); 111 | return false; 112 | } 113 | } 114 | ``` 115 | 116 |
117 | 118 | 3.SV+RV:有滑动冲突。 119 | 120 | 问题:内层在滑动时,外层也在滑动,滑动很卡顿。 121 | 122 | 分析: 123 | 124 | SV:重写了onInterceptTouchEvent方法。当Y轴移动距离大于最小滑动距离时,就会拦截事件,否则向子View传递。 125 | 126 | RV:没有重写dispatchTouchEvent方法。 127 | 128 |
129 | 130 | 解决: 131 | 132 | **内部拦截:内部滑动时,通过reDITE设置为true使事件向子View分发。** 133 | 134 | 通过打印日志会发现:当内部滑动的时候,外部没有在滑动。效果实现。 135 | 136 | ``` 137 | public class SV_RV_inner extends RecyclerView { 138 | public SV_RV_inner(Context context) { 139 | super(context); 140 | } 141 | public SV_RV_inner(Context context, @Nullable AttributeSet attrs) { 142 | super(context, attrs); 143 | } 144 | @Override 145 | public boolean dispatchTouchEvent(MotionEvent ev) { 146 | getParent().requestDisallowInterceptTouchEvent(true); 147 | if (ev.getAction() == MotionEvent.ACTION_MOVE) { 148 | Log.d("SV_RV", "dispatchTouchEvent: 内层在滑动++"); 149 | } 150 | return super.dispatchTouchEvent(ev); 151 | } 152 | } 153 | ``` 154 | 155 |
156 | 157 | 4.VP+VP:没有滑动冲突。 158 | 159 | 分析:打印日志发现:外部滑动的时候内部没有滑动,内部滑动的时候外部没有滑动。 160 | 161 |
162 | 163 | 综上,同一方向有滑动冲突的有两个例子: 164 | * 只有一层能滑动的例子:SV+SV 165 | * 内外层同时滑动很卡顿的例子:SV+RV 166 | 167 |
168 | 169 | ### 不同方向: 170 | 171 | 核心点: 172 | 173 | 判断谁来拦截:根据滑动是水平滑动还是竖直滑动来判断到底由谁来拦截事件。 174 | 175 | 判断滑动方向: 176 | * 根据滑动过程中两点之间的坐标 177 | * 滑动路径和水平方向所形成的夹角(滑动角度) 178 | * 水平和竖直方向距离差(距离差)(常用) 179 | * 水平和竖直方向速度差(速度差) 180 | 181 | 滑动冲突出现的根本原因: 182 | * 上层View拦截了下层View导致下层View无法滑动。 183 | 184 |
185 | 186 | 1.SRL+VP: 187 | 188 | 问题:VP左下右下滑动时,SRL也在上下滑动。SRL拦截掉了VP的滑动事件。 189 | 190 | 分析:SRL源码:Y轴大于最小滑动距离时,父View拦截事件,否则不拦截。 191 | 192 |
193 | 194 | 解决: 195 | 196 | **内部拦截:** 197 | 198 | SRL_VP_outer: 199 | ``` 200 | public class SRL_VP_outer extends SwipeRefreshLayout { 201 | public SRL_VP_outer(Context context) { 202 | super(context); 203 | } 204 | public SRL_VP_outer(Context context, AttributeSet attrs) { 205 | super(context, attrs); 206 | } 207 | @Override 208 | public boolean onInterceptTouchEvent(MotionEvent ev) { 209 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { 210 | super.onInterceptTouchEvent(ev); 211 | return false; 212 | } 213 | return super.onInterceptTouchEvent(ev); 214 | } 215 | } 216 | ``` 217 | 218 | SRL_VP_inner: 219 | ``` 220 | public class SRL_VP_inner extends ViewPager { 221 | private float startX; 222 | private float startY; 223 | private float x; 224 | private float y; 225 | private float deltaX; 226 | private float deltaY; 227 | public SRL_VP_inner(Context context) { 228 | super(context); 229 | } 230 | public SRL_VP_inner(Context context, AttributeSet attrs) { 231 | super(context, attrs); 232 | } 233 | @Override 234 | public boolean dispatchTouchEvent(MotionEvent ev) { 235 | switch (ev.getAction()) { 236 | case MotionEvent.ACTION_DOWN: 237 | startX = ev.getX(); 238 | startY = ev.getY(); 239 | //注释1 240 | ViewCompat.setNestedScrollingEnabled(this, true); 241 | getParent().requestDisallowInterceptTouchEvent(true); 242 | break; 243 | case MotionEvent.ACTION_MOVE: 244 | x = ev.getX(); 245 | y = ev.getY(); 246 | deltaX = Math.abs(x - startX); 247 | deltaY = Math.abs(y - startY); 248 | if (deltaX < deltaY) { 249 | getParent().requestDisallowInterceptTouchEvent(false); 250 | } 251 | break; 252 | case MotionEvent.ACTION_UP: 253 | case MotionEvent.ACTION_CANCEL: 254 | break; 255 | } 256 | return super.dispatchTouchEvent(ev); 257 | } 258 | } 259 | ``` 260 | 注释1: 261 | 262 | * 因为SRL重写了requestDisallowInterceptTouchEvent这个方法, 263 | 264 | * ViewCompat.isNestedScrollingEnabled(mTarget)默认为false, 265 | 266 | * 导致super.requestDisallowInterceptTouchEvent(b)不执行, 267 | 268 | * 所以要设置ViewCompat.isNestedScrollingEnabled为true。 269 | 270 |
271 | 内部解决第一种方法:VP内部加这句:ViewCompat.setNestedScrollingEnabled(this, true); 272 | 273 | 内部解决第二种方法:重写SRL#reDITE。 274 | 275 | 因为SRL继承ViewGroup类, 276 | 277 | 所以仿照ViewGroup的reDITE重写SRL的reDITE方法,不写super,class拿到变量名”mGroupFlags”。 278 | 279 | ``` 280 | @Override 281 | public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { 282 | // super.requestDisallowInterceptTouchEvent(b); 283 | Class cls = ViewGroup.class; 284 | try { 285 | Field field = cls.getField("mGroupFlags"); 286 | int c = (int) field.get(this); 287 | if (disallowIntercept) { 288 | field.set(this, 2900051); 289 | } else { 290 | field.set(this, 2245715); 291 | } 292 | } catch (NoSuchFieldException e) { 293 | e.printStackTrace(); 294 | } catch (IllegalAccessException e) { 295 | e.printStackTrace(); 296 | } 297 | } 298 | ``` 299 | 300 | **外部拦截:** 301 | 302 | 参考链接:https://blog.csdn.net/u010386612/article/details/50548977 303 | 304 | SRL_VP_out_SRL: 305 | ``` 306 | public class SRL_VP_out_SRL extends SwipeRefreshLayout { 307 | private boolean mIsBeingDragged; 308 | private float initialX; 309 | private float initialY; 310 | private float x; 311 | private float y; 312 | private float deltaX; 313 | private float deltaY; 314 | private int mTouchSlop; 315 | boolean isVpDragged = false; 316 | public SRL_VP_out_SRL(Context context) { 317 | super(context); 318 | } 319 | public SRL_VP_out_SRL(Context context, AttributeSet attrs) { 320 | super(context, attrs); 321 | mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); 322 | } 323 | @Override 324 | public boolean onInterceptTouchEvent(MotionEvent ev) { 325 | switch (ev.getAction()) { 326 | case MotionEvent.ACTION_DOWN: 327 | initialX = ev.getX(); 328 | initialY = ev.getY(); 329 | isVpDragged = false; 330 | break; 331 | case MotionEvent.ACTION_MOVE: 332 | //只要手指不离开就一直返回false 333 | if (isVpDragged) 334 | return false; 335 | x = ev.getX(); 336 | y = ev.getY(); 337 | deltaX = Math.abs(x - initialX); 338 | deltaY = Math.abs(y - initialY); 339 | if (deltaX > deltaY) { 340 | isVpDragged = true; 341 | return false; 342 | } 343 | break; 344 | case MotionEvent.ACTION_UP: 345 | case MotionEvent.ACTION_CANCEL: 346 | isVpDragged = false; 347 | break; 348 | } 349 | return super.onInterceptTouchEvent(ev); 350 | } 351 | } 352 | ``` 353 |
354 | 355 | 2.SV+VP:没有冲突。 356 | 357 |
358 | 359 | 3.VP+SV:没有冲突。 360 | 361 |
362 | 363 | 4.VP+LV:没有冲突。 364 | 365 | 366 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | defaultConfig { 6 | applicationId "com.example.ruru.android_slidingconflictdemo" 7 | minSdkVersion 23 8 | targetSdkVersion 26 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(dir: 'libs', include: ['*.jar']) 23 | implementation 'com.android.support:appcompat-v7:26.1.0' 24 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 25 | implementation 'com.android.support:support-v4:26.1.0' 26 | implementation 'com.android.support:design:26.1.0' 27 | testImplementation 'junit:junit:4.12' 28 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 29 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 30 | implementation 'com.facebook.fresco:fresco:1.13.0' 31 | } 32 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/example/ruru/android_slidingconflictdemo/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.example.ruru.android_slidingconflictdemo", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | 8 | import com.example.ruru.android_slidingconflictdemo.differentDirection.OuterTestActivity; 9 | import com.example.ruru.android_slidingconflictdemo.differentDirection.SRL_VP; 10 | import com.example.ruru.android_slidingconflictdemo.differentDirection.VP_LV; 11 | import com.example.ruru.android_slidingconflictdemo.differentDirection.VP_SV; 12 | import com.example.ruru.android_slidingconflictdemo.sameDirection.SRL_RV; 13 | import com.example.ruru.android_slidingconflictdemo.sameDirection.SRL_SV; 14 | import com.example.ruru.android_slidingconflictdemo.sameDirection.SV_RV; 15 | import com.example.ruru.android_slidingconflictdemo.sameDirection.SV_SV; 16 | import com.example.ruru.android_slidingconflictdemo.sameDirection.VP_VP; 17 | import com.example.ruru.android_slidingconflictdemo.test.MethodTestActivity; 18 | 19 | 20 | public class MainActivity extends AppCompatActivity { 21 | 22 | @Override 23 | protected void onCreate(Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | setContentView(R.layout.activity_main); 26 | } 27 | 28 | //SameDirection 29 | public void SRL_SV(View v) { 30 | startActivity(new Intent(this, SRL_SV.class)); 31 | } 32 | 33 | public void SRL_RV(View v) { 34 | startActivity(new Intent(this, SRL_RV.class)); 35 | } 36 | 37 | public void SV_SV(View v) { 38 | startActivity(new Intent(this, SV_SV.class)); 39 | } 40 | 41 | public void SV_RV(View v) { 42 | startActivity(new Intent(this, SV_RV.class)); 43 | } 44 | 45 | // public void SV_LV(View v) { 46 | // startActivity(new Intent(this, SV_LV.class)); 47 | // } 48 | 49 | public void VP_VP(View v) { 50 | startActivity(new Intent(this, VP_VP.class)); 51 | } 52 | 53 | //DifferentDirection 54 | public void SRL_VP(View v) { 55 | startActivity(new Intent(this, SRL_VP.class)); 56 | } 57 | 58 | public void VP_SV(View v) { 59 | startActivity(new Intent(this, VP_SV.class)); 60 | } 61 | 62 | public void VP_LV(View v) { 63 | startActivity(new Intent(this, VP_LV.class)); 64 | } 65 | 66 | public void out_test(View v) { 67 | startActivity(new Intent(this, OuterTestActivity.class)); 68 | } 69 | 70 | //test 71 | public void METHOD_TEST(View v) { 72 | startActivity(new Intent(this, MethodTestActivity.class)); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/adapter/SubRvAdapter.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.adapter; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.TextView; 9 | 10 | import com.example.ruru.android_slidingconflictdemo.R; 11 | 12 | import java.util.List; 13 | 14 | public class SubRvAdapter extends RecyclerView.Adapter { 15 | 16 | private Context context; 17 | private List list; 18 | private final LayoutInflater inflater; 19 | 20 | public SubRvAdapter(Context context, List list) { 21 | this.context = context; 22 | this.list = list; 23 | inflater = LayoutInflater.from(context); 24 | } 25 | 26 | @Override 27 | public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 28 | View view = inflater.inflate(R.layout.item, parent, false); 29 | return new MyViewHolder(view); 30 | } 31 | 32 | @Override 33 | public void onBindViewHolder(MyViewHolder holder, int position) { 34 | holder.tv.setText(list.get(position)); 35 | } 36 | 37 | @Override 38 | public int getItemCount() { 39 | return list.size(); 40 | } 41 | 42 | class MyViewHolder extends RecyclerView.ViewHolder { 43 | 44 | private final TextView tv; 45 | 46 | public MyViewHolder(View itemView) { 47 | super(itemView); 48 | 49 | tv = itemView.findViewById(R.id.tv); 50 | 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/adapter/SubVpAdapter.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.adapter; 2 | 3 | import android.support.v4.app.Fragment; 4 | import android.support.v4.app.FragmentManager; 5 | import android.support.v4.app.FragmentPagerAdapter; 6 | 7 | import java.util.List; 8 | 9 | public class SubVpAdapter extends FragmentPagerAdapter { 10 | 11 | private List list; 12 | 13 | public SubVpAdapter(FragmentManager fm, List list) { 14 | super(fm); 15 | this.list = list; 16 | } 17 | 18 | @Override 19 | public Fragment getItem(int position) { 20 | return list.get(position); 21 | } 22 | 23 | @Override 24 | public int getCount() { 25 | return list.size(); 26 | } 27 | 28 | @Override 29 | public CharSequence getPageTitle(int position) { 30 | return position == 0 ? "左边" : "右边"; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/data/DataModel.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.data; 2 | 3 | import android.support.v4.app.Fragment; 4 | 5 | import com.example.ruru.android_slidingconflictdemo.fragment.AFragment; 6 | import com.example.ruru.android_slidingconflictdemo.fragment.BFragment; 7 | import com.example.ruru.android_slidingconflictdemo.fragment.CFragment; 8 | import com.example.ruru.android_slidingconflictdemo.fragment.DFragment; 9 | import com.example.ruru.android_slidingconflictdemo.fragment.EFragment; 10 | import com.example.ruru.android_slidingconflictdemo.fragment.FFragment; 11 | import com.example.ruru.android_slidingconflictdemo.fragment.GFragment; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | public class DataModel { 17 | 18 | public static List getStringList1() { 19 | List list = new ArrayList<>(); 20 | for (int i = 0; i < 50; i++) { 21 | list.add("item" + i); 22 | } 23 | return list; 24 | } 25 | 26 | public static List getStringList2() { 27 | List list = new ArrayList<>(); 28 | for (int i = 0; i < 20; i++) { 29 | list.add("你好" + i); 30 | } 31 | return list; 32 | } 33 | 34 | public static List getFragmentList1() { 35 | List list = new ArrayList(); 36 | list.add(new AFragment()); 37 | list.add(new BFragment()); 38 | return list; 39 | } 40 | 41 | public static List getFragmentList2() { 42 | List list = new ArrayList(); 43 | list.add(new CFragment()); 44 | list.add(new DFragment()); 45 | return list; 46 | } 47 | 48 | public static List getFragmentList3() { 49 | List list = new ArrayList(); 50 | list.add(new FFragment()); 51 | list.add(new CFragment()); 52 | return list; 53 | } 54 | 55 | public static List getFragmentList4() { 56 | List list = new ArrayList(); 57 | list.add(new EFragment()); 58 | list.add(new GFragment()); 59 | return list; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/differentDirection/OuterTestActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.differentDirection; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | 6 | import com.example.ruru.android_slidingconflictdemo.R; 7 | import com.example.ruru.android_slidingconflictdemo.differentUI.OutSRL; 8 | import com.example.ruru.android_slidingconflictdemo.differentUI.SRL_VP_inner; 9 | import com.example.ruru.android_slidingconflictdemo.differentUI.SRL_VP_outer; 10 | 11 | public class OuterTestActivity extends AppCompatActivity { 12 | 13 | private OutSRL swipeRefreshLayout; 14 | 15 | @Override 16 | protected void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.activity_outer_test); 19 | 20 | initView(); 21 | } 22 | 23 | private void initView() { 24 | swipeRefreshLayout = (OutSRL) findViewById(R.id.swipeRefreshLayout); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/differentDirection/SRL_VP.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.differentDirection; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | import android.support.v4.widget.SwipeRefreshLayout; 6 | import android.support.v7.app.AppCompatActivity; 7 | 8 | import com.example.ruru.android_slidingconflictdemo.R; 9 | import com.example.ruru.android_slidingconflictdemo.adapter.SubVpAdapter; 10 | import com.example.ruru.android_slidingconflictdemo.data.DataModel; 11 | import com.example.ruru.android_slidingconflictdemo.differentUI.SRL_VP_out_SRL; 12 | import com.example.ruru.android_slidingconflictdemo.differentUI.SRL_VP_outer; 13 | import com.example.ruru.android_slidingconflictdemo.differentUI.SRL_VP_inner; 14 | 15 | public class SRL_VP extends AppCompatActivity { 16 | 17 | private SRL_VP_outer swipeRefreshLayout; 18 | private SRL_VP_inner viewPager; 19 | 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | setContentView(R.layout.activity_srl_vp); 24 | initView(); 25 | initData(); 26 | } 27 | 28 | private void initView() { 29 | swipeRefreshLayout = (SRL_VP_outer) findViewById(R.id.swipeRefreshLayout); 30 | viewPager = (SRL_VP_inner) findViewById(R.id.viewPager); 31 | } 32 | 33 | private void initData() { 34 | viewPager.setAdapter(new SubVpAdapter(getSupportFragmentManager(), DataModel.getFragmentList1())); 35 | swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { 36 | @Override 37 | public void onRefresh() { 38 | swipeRefreshLayout.setRefreshing(false); 39 | } 40 | }); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/differentDirection/VP_LV.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.differentDirection; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | import android.support.v7.app.AppCompatActivity; 6 | 7 | import com.example.ruru.android_slidingconflictdemo.R; 8 | import com.example.ruru.android_slidingconflictdemo.adapter.SubVpAdapter; 9 | import com.example.ruru.android_slidingconflictdemo.data.DataModel; 10 | 11 | public class VP_LV extends AppCompatActivity { 12 | 13 | private ViewPager viewPager; 14 | 15 | @Override 16 | protected void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.activity_vp_lv); 19 | initView(); 20 | initData(); 21 | } 22 | 23 | private void initView() { 24 | viewPager = findViewById(R.id.viewPager); 25 | } 26 | 27 | private void initData() { 28 | viewPager.setAdapter(new SubVpAdapter(getSupportFragmentManager(), DataModel.getFragmentList4())); 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/differentDirection/VP_SV.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.differentDirection; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | import android.support.v7.app.AppCompatActivity; 6 | 7 | import com.example.ruru.android_slidingconflictdemo.R; 8 | import com.example.ruru.android_slidingconflictdemo.adapter.SubVpAdapter; 9 | import com.example.ruru.android_slidingconflictdemo.data.DataModel; 10 | 11 | public class VP_SV extends AppCompatActivity { 12 | 13 | private ViewPager viewPager; 14 | 15 | @Override 16 | protected void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.activity_vp_sv_3); 19 | initView(); 20 | initData(); 21 | } 22 | 23 | private void initView() { 24 | viewPager = findViewById(R.id.viewPager); 25 | } 26 | 27 | private void initData() { 28 | viewPager.setAdapter(new SubVpAdapter(getSupportFragmentManager(), DataModel.getFragmentList3())); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/differentUI/OutSRL.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.differentUI; 2 | 3 | import android.content.Context; 4 | import android.support.v4.widget.SwipeRefreshLayout; 5 | import android.util.AttributeSet; 6 | import android.util.Log; 7 | import android.view.MotionEvent; 8 | 9 | public class OutSRL extends SwipeRefreshLayout { 10 | 11 | public OutSRL(Context context) { 12 | super(context); 13 | } 14 | 15 | public OutSRL(Context context, AttributeSet attrs) { 16 | super(context, attrs); 17 | } 18 | 19 | @Override 20 | public boolean dispatchTouchEvent(MotionEvent ev) { 21 | Log.d(getClass().getName(), "dispatchTouchEvent: ++"); 22 | return super.dispatchTouchEvent(ev); 23 | } 24 | 25 | @Override 26 | public boolean onInterceptTouchEvent(MotionEvent ev) { 27 | Log.d(getClass().getName(), "onInterceptTouchEvent: ++"); 28 | return true; 29 | } 30 | 31 | @Override 32 | public boolean onTouchEvent(MotionEvent ev) { 33 | Log.d(getClass().getName(), "onTouchEvent: ++"); 34 | return super.onTouchEvent(ev); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/differentUI/SRL_VP_inner.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.differentUI; 2 | 3 | import android.content.Context; 4 | import android.support.v4.view.ViewCompat; 5 | import android.support.v4.view.ViewPager; 6 | import android.util.AttributeSet; 7 | import android.util.Log; 8 | import android.view.MotionEvent; 9 | 10 | public class SRL_VP_inner extends ViewPager { 11 | 12 | private float startX; 13 | private float startY; 14 | private float x; 15 | private float y; 16 | private float deltaX; 17 | private float deltaY; 18 | 19 | public SRL_VP_inner(Context context) { 20 | super(context); 21 | } 22 | 23 | public SRL_VP_inner(Context context, AttributeSet attrs) { 24 | super(context, attrs); 25 | } 26 | 27 | @Override 28 | public boolean dispatchTouchEvent(MotionEvent ev) { 29 | switch (ev.getAction()) { 30 | case MotionEvent.ACTION_DOWN: 31 | startX = ev.getX(); 32 | startY = ev.getY(); 33 | ViewCompat.setNestedScrollingEnabled(this, true); 34 | getParent().requestDisallowInterceptTouchEvent(true); 35 | break; 36 | case MotionEvent.ACTION_MOVE: 37 | x = ev.getX(); 38 | y = ev.getY(); 39 | deltaX = Math.abs(x - startX); 40 | deltaY = Math.abs(y - startY); 41 | if (deltaX < deltaY) { 42 | getParent().requestDisallowInterceptTouchEvent(false); 43 | } 44 | break; 45 | case MotionEvent.ACTION_UP: 46 | case MotionEvent.ACTION_CANCEL: 47 | break; 48 | } 49 | return super.dispatchTouchEvent(ev); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/differentUI/SRL_VP_out_SRL.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.differentUI; 2 | 3 | import android.content.Context; 4 | import android.support.v4.widget.SwipeRefreshLayout; 5 | import android.util.AttributeSet; 6 | import android.view.MotionEvent; 7 | import android.view.ViewConfiguration; 8 | 9 | public class SRL_VP_out_SRL extends SwipeRefreshLayout { 10 | 11 | private boolean mIsBeingDragged; 12 | private float initialX; 13 | private float initialY; 14 | private float x; 15 | private float y; 16 | private float deltaX; 17 | private float deltaY; 18 | private int mTouchSlop; 19 | boolean isVpDragged = false; 20 | 21 | public SRL_VP_out_SRL(Context context) { 22 | super(context); 23 | } 24 | 25 | public SRL_VP_out_SRL(Context context, AttributeSet attrs) { 26 | super(context, attrs); 27 | mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); 28 | } 29 | 30 | @Override 31 | public boolean onInterceptTouchEvent(MotionEvent ev) { 32 | switch (ev.getAction()) { 33 | case MotionEvent.ACTION_DOWN: 34 | initialX = ev.getX(); 35 | initialY = ev.getY(); 36 | isVpDragged = false; 37 | break; 38 | case MotionEvent.ACTION_MOVE: 39 | //只要手指不离开就一直返回false 40 | if (isVpDragged) 41 | return false; 42 | x = ev.getX(); 43 | y = ev.getY(); 44 | deltaX = Math.abs(x - initialX); 45 | deltaY = Math.abs(y - initialY); 46 | if (deltaX > deltaY) { 47 | isVpDragged = true; 48 | return false; 49 | } 50 | break; 51 | case MotionEvent.ACTION_UP: 52 | case MotionEvent.ACTION_CANCEL: 53 | isVpDragged = false; 54 | break; 55 | } 56 | return super.onInterceptTouchEvent(ev); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/differentUI/SRL_VP_outer.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.differentUI; 2 | 3 | import android.content.Context; 4 | import android.support.v4.widget.SwipeRefreshLayout; 5 | import android.util.AttributeSet; 6 | import android.util.Log; 7 | import android.view.MotionEvent; 8 | import android.view.ViewGroup; 9 | 10 | import java.lang.reflect.Field; 11 | 12 | public class SRL_VP_outer extends SwipeRefreshLayout { 13 | public SRL_VP_outer(Context context) { 14 | super(context); 15 | } 16 | 17 | public SRL_VP_outer(Context context, AttributeSet attrs) { 18 | super(context, attrs); 19 | } 20 | 21 | @Override 22 | public boolean onInterceptTouchEvent(MotionEvent ev) { 23 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { 24 | super.onInterceptTouchEvent(ev); 25 | return false; 26 | } 27 | return super.onInterceptTouchEvent(ev); 28 | } 29 | 30 | @Override 31 | public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { 32 | // super.requestDisallowInterceptTouchEvent(b); 33 | Class cls = ViewGroup.class; 34 | try { 35 | Field field = cls.getField("mGroupFlags"); 36 | int c = (int) field.get(this); 37 | if (disallowIntercept) { 38 | field.set(this, 2900051); 39 | } else { 40 | field.set(this, 2245715); 41 | } 42 | } catch (NoSuchFieldException e) { 43 | e.printStackTrace(); 44 | } catch (IllegalAccessException e) { 45 | e.printStackTrace(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/fragment/AFragment.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.Fragment; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | 9 | import com.example.ruru.android_slidingconflictdemo.R; 10 | 11 | public class AFragment extends Fragment { 12 | 13 | public AFragment() { 14 | // Required empty public constructor 15 | } 16 | 17 | @Override 18 | public void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | 21 | } 22 | 23 | @Override 24 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 25 | Bundle savedInstanceState) { 26 | return inflater.inflate(R.layout.fragment_a, container, false); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/fragment/BFragment.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.fragment; 2 | 3 | 4 | import android.os.Bundle; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | import com.example.ruru.android_slidingconflictdemo.R; 11 | 12 | /** 13 | * A simple {@link Fragment} subclass. 14 | */ 15 | public class BFragment extends Fragment { 16 | 17 | 18 | public BFragment() { 19 | // Required empty public constructor 20 | } 21 | 22 | 23 | @Override 24 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 25 | Bundle savedInstanceState) { 26 | // Inflate the layout for this fragment 27 | return inflater.inflate(R.layout.fragment_b, container, false); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/fragment/CFragment.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.fragment; 2 | 3 | 4 | import android.os.Bundle; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | import com.example.ruru.android_slidingconflictdemo.R; 11 | 12 | /** 13 | * A simple {@link Fragment} subclass. 14 | */ 15 | public class CFragment extends Fragment { 16 | 17 | @Override 18 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 19 | Bundle savedInstanceState) { 20 | return inflater.inflate(R.layout.fragment_c, container, false); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/fragment/DFragment.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.Fragment; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | 9 | import com.example.ruru.android_slidingconflictdemo.R; 10 | 11 | public class DFragment extends Fragment { 12 | 13 | @Override 14 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 15 | Bundle savedInstanceState) { 16 | return inflater.inflate(R.layout.fragment_d, container, false); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/fragment/EFragment.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.fragment; 2 | 3 | 4 | import android.os.Bundle; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.ArrayAdapter; 10 | import android.widget.ListView; 11 | 12 | import com.example.ruru.android_slidingconflictdemo.R; 13 | import com.example.ruru.android_slidingconflictdemo.data.DataModel; 14 | 15 | import java.util.List; 16 | 17 | /** 18 | * ListView 19 | */ 20 | public class EFragment extends Fragment { 21 | 22 | 23 | public EFragment() { 24 | // Required empty public constructor 25 | } 26 | 27 | 28 | @Override 29 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 30 | Bundle savedInstanceState) { 31 | View view = inflater.inflate(R.layout.fragment_e, container, false); 32 | ListView listView = view.findViewById(R.id.listView); 33 | listView.setAdapter(new ArrayAdapter(getActivity(), R.layout.item, R.id.tv, DataModel.getStringList1())); 34 | return view; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/fragment/FFragment.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.Fragment; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | 9 | import com.example.ruru.android_slidingconflictdemo.R; 10 | 11 | /** 12 | * 有ScrollView 13 | */ 14 | public class FFragment extends Fragment { 15 | 16 | @Override 17 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 18 | Bundle savedInstanceState) { 19 | return inflater.inflate(R.layout.fragment_f, container, false); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/fragment/GFragment.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.fragment; 2 | 3 | 4 | import android.os.Bundle; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.ArrayAdapter; 10 | import android.widget.ListView; 11 | 12 | import com.example.ruru.android_slidingconflictdemo.R; 13 | import com.example.ruru.android_slidingconflictdemo.data.DataModel; 14 | 15 | /** 16 | * ListView 17 | */ 18 | public class GFragment extends Fragment { 19 | 20 | 21 | public GFragment() { 22 | // Required empty public constructor 23 | } 24 | 25 | 26 | @Override 27 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 28 | Bundle savedInstanceState) { 29 | View view = inflater.inflate(R.layout.fragment_g, container, false); 30 | ListView listView = view.findViewById(R.id.listView); 31 | listView.setAdapter(new ArrayAdapter(getActivity(), R.layout.item, R.id.tv, DataModel.getStringList2())); 32 | return view; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/sameDirection/SRL_RV.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.sameDirection; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.widget.SwipeRefreshLayout; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.util.Log; 9 | import android.view.ViewTreeObserver; 10 | 11 | import com.example.ruru.android_slidingconflictdemo.R; 12 | import com.example.ruru.android_slidingconflictdemo.adapter.SubRvAdapter; 13 | import com.example.ruru.android_slidingconflictdemo.data.DataModel; 14 | 15 | public class SRL_RV extends AppCompatActivity { 16 | 17 | private SwipeRefreshLayout mRefreshLayout; 18 | private RecyclerView mRecyclerView; 19 | 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | setContentView(R.layout.activity_srl_rv); 24 | 25 | initView(); 26 | initData(); 27 | } 28 | 29 | private void initView() { 30 | mRefreshLayout = findViewById(R.id.swipeRefreshLayout); 31 | mRecyclerView = findViewById(R.id.recyclerView); 32 | } 33 | 34 | private void initData() { 35 | mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)); 36 | mRecyclerView.setAdapter(new SubRvAdapter(this, DataModel.getStringList1())); 37 | 38 | mRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { 39 | @Override 40 | public void onRefresh() { 41 | 42 | mRefreshLayout.setRefreshing(false); 43 | } 44 | }); 45 | 46 | mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { 47 | @Override 48 | public void onScrollStateChanged(RecyclerView recyclerView, int newState) { 49 | super.onScrollStateChanged(recyclerView, newState); 50 | 51 | // Log.d("SRL_RV", "recyclerViewTime=" + new Date().getTime()); 52 | Log.d("SRL_RV", "recyclerView 正在滚动"); 53 | } 54 | }); 55 | 56 | mRefreshLayout.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() { 57 | @Override 58 | public void onScrollChanged() { 59 | Log.d("SRL_RV", "swipeRefreshLayout 正在滚动"); 60 | } 61 | }); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/sameDirection/SRL_SV.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.sameDirection; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.widget.SwipeRefreshLayout; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.util.Log; 7 | import android.view.View; 8 | import android.view.ViewTreeObserver; 9 | import android.widget.ArrayAdapter; 10 | import android.widget.ListView; 11 | import android.widget.ScrollView; 12 | 13 | import com.example.ruru.android_slidingconflictdemo.R; 14 | import com.example.ruru.android_slidingconflictdemo.data.DataModel; 15 | 16 | import java.util.Date; 17 | 18 | public class SRL_SV extends AppCompatActivity { 19 | 20 | private SwipeRefreshLayout mRefreshLayout; 21 | private ScrollView mScrollView; 22 | 23 | @Override 24 | protected void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | setContentView(R.layout.activity_srl_sv); 27 | 28 | mRefreshLayout = findViewById(R.id.mRefreshLayout); 29 | mScrollView = findViewById(R.id.mScrollView); 30 | 31 | mRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { 32 | @Override 33 | public void onRefresh() { 34 | 35 | Log.d("SRL_SV", "refreshTime=" + new Date().getTime()); 36 | 37 | mRefreshLayout.setRefreshing(false); 38 | } 39 | }); 40 | 41 | mRefreshLayout.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() { 42 | @Override 43 | public void onScrollChanged() { 44 | Log.d("SRL_SV", "swipeRefreshLayout 正在滚动"); 45 | } 46 | }); 47 | 48 | mScrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() { 49 | @Override 50 | public void onScrollChanged() { 51 | if (mScrollView.getScrollY() == 0) { 52 | 53 | Log.d("SRL_SV", "scrollTime=" + new Date().getTime()); 54 | Log.d("SRL_SV", "scrollView 正在滚动"); 55 | 56 | } 57 | } 58 | }); 59 | 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/sameDirection/SV_LV.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.sameDirection; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.view.View; 9 | import android.widget.ListView; 10 | 11 | import com.example.ruru.android_slidingconflictdemo.R; 12 | import com.example.ruru.android_slidingconflictdemo.adapter.SubRvAdapter; 13 | import com.example.ruru.android_slidingconflictdemo.data.DataModel; 14 | import com.example.ruru.android_slidingconflictdemo.sameUI.SV_LV_inner; 15 | 16 | public class SV_LV extends AppCompatActivity { 17 | 18 | private SV_LV_inner rv; 19 | 20 | @Override 21 | protected void onCreate(@Nullable Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | setContentView(R.layout.activity_sv_lv); 24 | 25 | initView(); 26 | } 27 | 28 | private void initView() { 29 | rv = findViewById(R.id.rv); 30 | rv.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)); 31 | rv.setAdapter(new SubRvAdapter(this, DataModel.getStringList2())); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/sameDirection/SV_RV.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.sameDirection; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.support.v7.widget.LinearLayoutManager; 6 | 7 | import com.example.ruru.android_slidingconflictdemo.R; 8 | import com.example.ruru.android_slidingconflictdemo.adapter.SubRvAdapter; 9 | import com.example.ruru.android_slidingconflictdemo.data.DataModel; 10 | import com.example.ruru.android_slidingconflictdemo.sameUI.SV_RV_inner; 11 | import com.example.ruru.android_slidingconflictdemo.sameUI.SV_RV_outer; 12 | 13 | public class SV_RV extends AppCompatActivity { 14 | 15 | private SV_RV_outer mScrollView; 16 | private SV_RV_inner mRecyclerView; 17 | 18 | @Override 19 | protected void onCreate(Bundle savedInstanceState) { 20 | super.onCreate(savedInstanceState); 21 | setContentView(R.layout.activity_sv_rv); 22 | 23 | initView(); 24 | initData(); 25 | } 26 | 27 | private void initView() { 28 | mScrollView = findViewById(R.id.scrollView); 29 | mRecyclerView = findViewById(R.id.recyclerView); 30 | } 31 | 32 | private void initData() { 33 | mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)); 34 | mRecyclerView.setAdapter(new SubRvAdapter(this, DataModel.getStringList1())); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/sameDirection/SV_SV.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.sameDirection; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | 7 | import com.example.ruru.android_slidingconflictdemo.R; 8 | 9 | public class SV_SV extends AppCompatActivity { 10 | 11 | @Override 12 | protected void onCreate(@Nullable Bundle savedInstanceState) { 13 | super.onCreate(savedInstanceState); 14 | setContentView(R.layout.activity_sv_sv); 15 | 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/sameDirection/VP_VP.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.sameDirection; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | import android.support.v7.app.AppCompatActivity; 6 | 7 | import com.example.ruru.android_slidingconflictdemo.R; 8 | import com.example.ruru.android_slidingconflictdemo.adapter.SubVpAdapter; 9 | import com.example.ruru.android_slidingconflictdemo.data.DataModel; 10 | import com.example.ruru.android_slidingconflictdemo.sameUI.VP_VP_inner; 11 | 12 | public class VP_VP extends AppCompatActivity { 13 | 14 | private ViewPager mViewPager1; 15 | private VP_VP_inner mViewPager2; 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_vp_vp); 21 | 22 | initView(); 23 | initData(); 24 | } 25 | 26 | private void initData() { 27 | mViewPager1.setAdapter(new SubVpAdapter(getSupportFragmentManager(), DataModel.getFragmentList1())); 28 | mViewPager2.setAdapter(new SubVpAdapter(getSupportFragmentManager(), DataModel.getFragmentList2())); 29 | } 30 | 31 | private void initView() { 32 | mViewPager1 = findViewById(R.id.viewPager1); 33 | mViewPager2 = findViewById(R.id.viewPager2); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/sameUI/SV_LV_inner.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.sameUI; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.util.AttributeSet; 6 | import android.view.MotionEvent; 7 | import android.widget.ListView; 8 | 9 | public class SV_LV_inner extends RecyclerView { 10 | public SV_LV_inner(Context context) { 11 | super(context); 12 | } 13 | 14 | public SV_LV_inner(Context context, AttributeSet attrs) { 15 | super(context, attrs); 16 | } 17 | 18 | @Override 19 | public boolean dispatchTouchEvent(MotionEvent ev) { 20 | return super.dispatchTouchEvent(ev); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/sameUI/SV_LV_outer.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.sameUI; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.MotionEvent; 6 | import android.widget.ScrollView; 7 | 8 | public class SV_LV_outer extends ScrollView { 9 | public SV_LV_outer(Context context) { 10 | super(context); 11 | } 12 | 13 | public SV_LV_outer(Context context, AttributeSet attrs) { 14 | super(context, attrs); 15 | } 16 | 17 | @Override 18 | public boolean onInterceptTouchEvent(MotionEvent ev) { 19 | return super.onInterceptTouchEvent(ev); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/sameUI/SV_RV_inner.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.sameUI; 2 | 3 | import android.content.Context; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.util.AttributeSet; 7 | import android.util.Log; 8 | import android.view.MotionEvent; 9 | 10 | public class SV_RV_inner extends RecyclerView { 11 | 12 | public SV_RV_inner(Context context) { 13 | super(context); 14 | } 15 | 16 | public SV_RV_inner(Context context, @Nullable AttributeSet attrs) { 17 | super(context, attrs); 18 | } 19 | 20 | @Override 21 | public boolean dispatchTouchEvent(MotionEvent ev) { 22 | getParent().requestDisallowInterceptTouchEvent(true); 23 | if (ev.getAction() == MotionEvent.ACTION_MOVE) { 24 | Log.d("SV_RV", "dispatchTouchEvent: 内层在滑动++"); 25 | } 26 | return super.dispatchTouchEvent(ev); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/sameUI/SV_RV_outer.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.sameUI; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.util.Log; 6 | import android.view.MotionEvent; 7 | import android.widget.ScrollView; 8 | 9 | public class SV_RV_outer extends ScrollView { 10 | 11 | public SV_RV_outer(Context context) { 12 | super(context); 13 | } 14 | 15 | public SV_RV_outer(Context context, AttributeSet attrs) { 16 | super(context, attrs); 17 | } 18 | 19 | @Override 20 | public boolean onInterceptTouchEvent(MotionEvent ev) { 21 | if (ev.getAction() == MotionEvent.ACTION_MOVE) { 22 | Log.d("SV_RV", "onInterceptTouchEvent: 外层在滑动+"); 23 | } 24 | return super.onInterceptTouchEvent(ev); 25 | } 26 | 27 | @Override 28 | public boolean onTouchEvent(MotionEvent ev) { 29 | if (ev.getAction() == MotionEvent.ACTION_MOVE) { 30 | Log.d("SV_RV", "onInterceptTouchEvent: 外层在滑动++"); 31 | } 32 | return super.onTouchEvent(ev); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/sameUI/SV_SV_inner.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.sameUI; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.MotionEvent; 6 | import android.widget.ScrollView; 7 | 8 | import static android.view.MotionEvent.ACTION_DOWN; 9 | import static android.view.MotionEvent.ACTION_MOVE; 10 | 11 | public class SV_SV_inner extends ScrollView { 12 | public SV_SV_inner(Context context) { 13 | super(context); 14 | } 15 | 16 | public SV_SV_inner(Context context, AttributeSet attrs) { 17 | super(context, attrs); 18 | } 19 | 20 | @Override 21 | public boolean dispatchTouchEvent(MotionEvent ev) { 22 | return super.dispatchTouchEvent(ev); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/sameUI/SV_SV_outer.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.sameUI; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.MotionEvent; 6 | import android.widget.ScrollView; 7 | 8 | public class SV_SV_outer extends ScrollView { 9 | public SV_SV_outer(Context context) { 10 | super(context); 11 | } 12 | 13 | public SV_SV_outer(Context context, AttributeSet attrs) { 14 | super(context, attrs); 15 | } 16 | 17 | @Override 18 | public boolean onInterceptTouchEvent(MotionEvent ev) { 19 | super.onInterceptTouchEvent(ev); 20 | return false; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/sameUI/VP_VP_inner.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.sameUI; 2 | 3 | import android.content.Context; 4 | import android.support.v4.view.ViewPager; 5 | import android.util.AttributeSet; 6 | import android.util.Log; 7 | import android.view.MotionEvent; 8 | 9 | public class VP_VP_inner extends ViewPager { 10 | 11 | public VP_VP_inner(Context context) { 12 | super(context); 13 | } 14 | 15 | public VP_VP_inner(Context context, AttributeSet attributeSet) { 16 | super(context, attributeSet); 17 | } 18 | 19 | @Override 20 | public boolean dispatchTouchEvent(MotionEvent ev) { 21 | /*switch (ev.getAction()) { 22 | case MotionEvent.ACTION_DOWN: 23 | getParent().requestDisallowInterceptTouchEvent(true); 24 | break; 25 | case MotionEvent.ACTION_MOVE: 26 | int curPosition = this.getCurrentItem(); 27 | int count = this.getAdapter().getCount(); 28 | if (curPosition == count - 1 || curPosition == 0) { 29 | getParent().requestDisallowInterceptTouchEvent(false); 30 | } else { 31 | getParent().requestDisallowInterceptTouchEvent(true); 32 | } 33 | break; 34 | case MotionEvent.ACTION_UP: 35 | case MotionEvent.ACTION_CANCEL: 36 | break; 37 | }*/ 38 | if (ev.getAction() == MotionEvent.ACTION_MOVE) { 39 | Log.d("VP_VP", "dispatchTouchEvent: 内部在滑动++"); 40 | } 41 | return super.dispatchTouchEvent(ev); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/sameUI/VP_VP_outer.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.sameUI; 2 | 3 | import android.content.Context; 4 | import android.support.v4.view.ViewPager; 5 | import android.util.AttributeSet; 6 | import android.util.Log; 7 | import android.view.MotionEvent; 8 | 9 | public class VP_VP_outer extends ViewPager { 10 | public VP_VP_outer(Context context) { 11 | super(context); 12 | } 13 | 14 | public VP_VP_outer(Context context, AttributeSet attrs) { 15 | super(context, attrs); 16 | } 17 | 18 | @Override 19 | public boolean onInterceptTouchEvent(MotionEvent ev) { 20 | if (ev.getAction() == MotionEvent.ACTION_MOVE) { 21 | Log.d("VP_VP", "onInterceptTouchEvent: 外部在滑动+"); 22 | } 23 | return super.onInterceptTouchEvent(ev); 24 | } 25 | 26 | @Override 27 | public boolean onTouchEvent(MotionEvent ev) { 28 | if (ev.getAction() == MotionEvent.ACTION_MOVE) { 29 | Log.d("VP_VP", "onInterceptTouchEvent: 外部在滑动++"); 30 | } 31 | return super.onTouchEvent(ev); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ruru/android_slidingconflictdemo/test/MethodTestActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.ruru.android_slidingconflictdemo.test; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.util.Log; 6 | import android.view.MotionEvent; 7 | import android.view.View; 8 | import android.widget.Button; 9 | import android.widget.LinearLayout; 10 | 11 | import com.example.ruru.android_slidingconflictdemo.R; 12 | 13 | public class MethodTestActivity extends AppCompatActivity { 14 | 15 | private LinearLayout ll; 16 | private Button button; 17 | 18 | @Override 19 | protected void onCreate(Bundle savedInstanceState) { 20 | super.onCreate(savedInstanceState); 21 | setContentView(R.layout.activity_method_test); 22 | 23 | initView(); 24 | initData(); 25 | } 26 | 27 | private void initData() { 28 | ll.setOnTouchListener(new View.OnTouchListener() { 29 | @Override 30 | public boolean onTouch(View v, MotionEvent event) { 31 | Log.d("mt", "onTouch++"); 32 | return false; 33 | } 34 | }); 35 | 36 | ll.setOnClickListener(new View.OnClickListener() { 37 | @Override 38 | public void onClick(View v) { 39 | Log.d("mt", "onClick++"); 40 | } 41 | }); 42 | } 43 | 44 | private void initView() { 45 | ll = findViewById(R.id.ll); 46 | button = findViewById(R.id.button); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_hsv__lv.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_lv_vp.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 12 | 13 | 17 | 18 | 23 | 24 |