`
mengsina
  • 浏览: 188526 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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

阅读更多
引用: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=”fill_parent”
            android:layout_height=”wrap_content”
            android:layout_weight=”1″
            android:background=”@drawable/dotted_bg”
            android:focusableInTouchMode=”false”>
                        <LinearLayout   />
                        <LinearLayout   />
                        <LinearLayout  >
                        <ScrollView android:id=”@+id/child_scroll” 
                        android:layout_width=”fill_parent”
                        android:layout_height=”fill_parent”
                        android:background=”@drawable/text_box_bg”>
                    <TextView android:id=”@+id/text_description”
                        android:layout_width=”fill_parent”
                        android:layout_height=”fill_parent”
                        android:textColor=”@color/gray”
                        android:textSize=”12dip”
                        android:padding=”5dip”
                        android:scrollbars=”vertical”/>
                    <!–ScrollView>
                  </LinearLayout>
</ScrollView>

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

     parentScroll=(ScrollView)findViewById(R.id.parent_scroll);
     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) {
                    Log.v(TAG,”PARENT TOUCH”);
                    findViewById(R.id.child_scroll).getParent().requestDisallowInterceptTouchEvent(false);
                    return false;
                }
            });
            childScroll.setOnTouchListener(new View.OnTouchListener() {

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

Done …
分享到:
评论
6 楼 mengsina 2015-12-02  
Gamalack 写道
我们这里烦不了墙,看不到英文版的啊

推荐 过墙的浏览器 天行
5 楼 Gamalack 2015-11-07  
我们这里烦不了墙,看不到英文版的啊
4 楼 Gamalack 2015-11-07  
有没有demo啊,自己试了好久都没有弄出来
3 楼 mengsina 2015-07-28  
nvcxy_1225 写道
Thanks。very thanks

这个我都引用了好久的。呵呵,还能帮到你,很高兴
2 楼 nvcxy_1225 2015-07-24  
Thanks。very thanks
1 楼 baojiarui 2014-08-05  
Thanks

相关推荐

Global site tag (gtag.js) - Google Analytics