Android ScrollView嵌套ScrollView滚动的问题解决办法

引用:http://mengsina.iteye.com/blog/1707464

http://fenglog.com/article.asp?id=449

Android ScrollView嵌套ScrollView滚动的问题解决办法 
原文地址:http://trivedihardik.wordpress.com/2011/09/19/scrollview-inside-scrollview-scrolling-problem/

搞技术的多少看的懂E文,也不翻译了。

While designing rich layouts you might need to use two scrollview in your app. 
Well ideally its not advised to use two scrollview in a view. So try to avoid it.

Why this problem occurs ? :

When you put two scrollview android just get confused which scroll view is touched. So sometimes it gets unable to deliver touch event.

But even if the requirement forces you to make such layouts. Try this…

Say case is somewhat like this….

    <ScrollView
        android:id="@+id/parent_scroll"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@color/black"
        android:cacheColorHint="#00000000"
        android:fadingEdge="none"
        android:overScrollMode="never"
        android:scrollbars="none">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="vertical">

                <ScrollView
                    android:id="@+id/child_scroll"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_toRightOf="@+id/TextView001"
                    android:cacheColorHint="#00000000"
                    android:fadingEdge="none"
                    android:overScrollMode="never"
                    android:scrollbars="none">

                    <TextView
                        android:id="@+id/tv_detail"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:padding="15dp"
                        android:textColor="@color/cbWhite"
                        android:textSize="@dimen/cb_textSize_big"/>
                </ScrollView>

        </LinearLayout>
    </ScrollView>

Step 1 : Provide unique id to both the scrollview. 
Step 2 : get reference of that two scrollview in your activity.

    ScrollView parentScroll = (ScrollView) findViewById(R.id.parent_scroll);
    ScrollView childScroll = (ScrollView) findViewById(R.id.child_scroll);

Step 3: Now set touch listeners for both.

        parentScroll.setOnTouchListener(new View.OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {
                findViewById(R.id.child_scroll).getParent().requestDisallowInterceptTouchEvent(false);
                return false;
            }
        });
        childScroll.setOnTouchListener(new View.OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {
                // Disallow the touch request for parent scroll on touch of child view
                v.getParent().requestDisallowInterceptTouchEvent(true);
                return false;
            }
        });

Done …

时间: 2024-08-08 09:25:27

Android ScrollView嵌套ScrollView滚动的问题解决办法的相关文章

Android仿小米商城商品详情界面UI,ScrollView嵌套ScrollView/WebView/ListView

最近公司没事,研究了下多嵌套滚动组件的事件分发,虽然以前也接触过,但都是拿网上的用,也是特别简单的,正好朋友也需要,就研究了下 这个Demo也不是很完善,放上来也是让各位大牛给指点一下,优化优化 使用情景: 小米商城商品详情界面,界面看似ScrollView,但当正常滚动到底部时,提示继续上拉显示更多详情,上拉后直接滚动到第二屏,第二屏是个ViewPager,ViewPager里面的各个pager有的是WebView有的是ListView,有的是ScrollView,一开始想想就特别头晕,后来理

scrollview嵌套listview滚动冲突解决方案;

主activity页面: package com.example.scrollviewlistview; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; i

Android ADB 5037端口被占用问题解决办法:改端口号

近使用ADB时报错“error: cannot connect to daemon: No error”,发现只要运行酷狗音乐播放器就会出现.所以轻易的就想到又是端口被占了,之前酷狗kadb进程占用5037端口,我设置过禁止其运行权限,所以很长一段时间使用ADB都没出现过问题.经过探查,发现是酷狗主程序调用ADB导致的,普通方法是不行的,看来不用大招是不行了...好吧,5037我不用了,换个端口吧.现在电脑中大部分软件都会占用ADB,至于干什么,无非就是想往手机塞些应用罢了,但很多时候我们又不得

ScrollView如何嵌套ScrollView

android开发中ScrollView嵌套ScrollView是android最常用的功能,众所周知,android 里两个相同方向的ScrollView是不能嵌套的,那要是有这样的需求怎么办? 目前做的这个只支持两个ScrollView嵌套,两个以上还有待改进,能套两个就已经能满足很多需求了,呵呵,另外现在只做了纵向scrollview的支持,横向的还没做 package com.example.easy.view; /** * Created by admin on 2016/5/10.

Android 开发遇到的问题及解决办法

Failed to resolve: com.android.support:appcompat-v7:23.4.0 问题解决办法: 1.在Android SDK Manager中找到对应的SDK版本,并且选中Extras中的Android Support Repository和Google Repository安装包. 2.选择 Sync Project with Gradle Files,重新编译,然后启动即可解决. adb not responding if youd like to re

Android ViewPager和ScrollView嵌套滚动问题解决方案

问题描述: 我的嵌套是ViewPager-->ScrollView-->ViewPager. 首先最里面的ViewPager水平滚动时总是会触发最外层的ViewPager滚动,看了网上很多的解决办法基本上是一样的,需要自定义ViewPager. import android.content.Context; import android.graphics.PointF; import android.support.v4.view.ViewPager; import android.util.

Android开发:ScrollView嵌套GridView的解决办法

Android开发:ScrollView嵌套GridView的解决办法 前些日子在开发中用到了需要ScrollView嵌套GridView的情况,由于这两款控件都自带滚动条,当他们碰到一起的时候便会出问题,即GridView会显示不全. 解决办法,自定义一个GridView控件 public class MyGridView extends GridView {      public MyGridView(Context context, AttributeSet attrs) {      

Android Scrollview嵌套RecyclerView导致滑动卡顿问题解决

一个比较长的界面一般都是Scrollview嵌套RecyclerView来解决.不过这样的UI并不是我们开发人员想看到的,实际上嵌套之后.因为Scrollview和RecyclerView都是滑动控件.会有一点滑动上的冲突.导致滑动起来有些卡顿.这个时候.我们重写一下LayoutManager就行了 例如: [java] view plain copy LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getAct

【Android - 问题解决】之ScrollView嵌套ListView时总是自动滑动到ListView顶部的问题

最近做了一个项目,里面有一个ScrollView嵌套ListView的布局. 做出来之后发现,进入这个界面之后,总是自动滑动到ListView的顶部,而ScrollView中位于ListView上面的一些控件就被挤到屏幕外面去了. 解决这个问题的方法如下: 在JAVA代码中,调用ScrollView对象的这个方法: scrollView.smoothScrollTo(0, 0);