Android ScrollView Nested ScrollView scrolling Problem solving method

Source: Internet
Author: User

Reference: http://mengsina.iteye.com/blog/1707464

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


Android ScrollView Nested ScrollView scrolling Problem solving method
Original address: http://trivedihardik.wordpress.com/2011/09/19/scrollview-inside-scrollview-scrolling-problem/

How much of the technology to read e-wen, also do not translate.

While designing rich layouts your might need to use the ScrollView in your app.
Well ideally it not advised to use the ScrollView in a view. So try to avoid it.

Why this problem occurs? :

When you put the 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 and make such layouts. Try this ...

Say case was somewhat like this ....

    <ScrollViewAndroid: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">        <LinearLayoutAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"android:gravity= "Center"android:orientation= "vertical">                 <ScrollViewAndroid: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">                    <TextViewAndroid: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, scrollview in your activity.

    ScrollView Parentscroll = (ScrollView) Findviewbyid (r.id.parent_scroll);     = (ScrollView) Findviewbyid (R.id.child_scroll);



Step 3:now Set touch listeners for both.

Parentscroll.setontouchlistener (NewView.ontouchlistener () { Public BooleanOnTouch (View V, motionevent event) {Findviewbyid (r.id.child_scroll). GetParent (). Requestdisallowinterc Epttouchevent (false); return false;        }        }); Childscroll.setontouchlistener (NewView.ontouchlistener () { Public BooleanOnTouch (View V, motionevent event) {//Disallow the touch request for parent scroll on Touch of child viewV.getparent (). Requestdisallowintercepttouchevent (true); return false; }        });



Done ...

Android ScrollView Nested ScrollView scrolling Problem solving method

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.