zoukankan      html  css  js  c++  java
  • 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 …

  • 相关阅读:
    应用程序无法启动,因为应用程序的并行配置不正确
    dotnetcore发布报版本错误
    C# 间隔时间休眠
    windows程序崩溃生成dump文件
    C# 委托的使用
    C# winform程序开机自启的方法
    win10Ping端口和查看端口占用
    415 DOM 查找列表框、下拉菜单控件、对表格元素/表单控件进行增删改操作、创建元素并且复制节点与删除、 对表格操作、通用性和标准的事件监听方法(点击后弹窗效果以及去掉效果)
    413 重温HTML + css 考试 + 访问HTML元素
    412 6个题 BOM and DOM 定义计数器 网页跳转 网页前进后退
  • 原文地址:https://www.cnblogs.com/niray/p/4600391.html
Copyright © 2011-2022 走看看