I\'m trying to put a ScrollView inside another ScrollView and I tried the answers found on this site but it still doesn\'t seems to work completely. Here is the XML:
Having a Scroll View inside another another Scroll View is not a good practice. However the code you have used could work in some cases. But it might fail when you are having multiple elements. In that case, it might not be able to identify the gesture.
However, you can try this answer, if it helps ScrollView Inside ScrollView. It disables the parent ScrollView's touch, when a touch for the child is identified. Also have a look at this post if it helps.
Old Question though, I am posting what worked for me,I understand the issue Coz i have gone through it too, I just removed the ScrollView for TextView in XML, rather implemented scrolling feature for TextView in java code. Thus, XML would be:
<TextView
android:id="@+id/textViewDirectoryDetailName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/red" />
<LinearLayout
android:id="@+id/linearLayoutDirectoryDetailContainImage"
android:layout_width="300dp"
android:layout_height="200dp"
android:layout_gravity="center_vertical|center_horizontal"
android:background="@drawable/general_image"
android:gravity="center"
android:orientation="vertical" >
</LinearLayout>
<TextView
android:id="@+id/textViewDirectoryDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:autoLink="phone"
android:text="098 123 45 678"
android:textAppearance="?android:attr/textAppearanceLarge" />
and the Java Code would be
TextView extViewDD =
(TextView)findViewById(R.id.textViewDirectoryDescription);
//for Scrolling of textView
textViewDD.setMovementMethod(new ScrollingMovementMethod());
//to stop parent linearlayout scrollview when touched on textview
textViewDD.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});
I use RectF to test whether you finger locates in the range of your child_view.
I've used it for a case that a mix between scrollview and viewpager(that contains two pages with recycleviews).
Try these codes and you will get what you wanna.
findViewById(R.id.parent_view).setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
View childV = findViewById(R.id.child_view);
if (childV != null) {
int[] l = new int[2];
childV.getLocationOnScreen(l);
RectF rect = new RectF(l[0], l[1], l[0] + childV.getWidth(), l[1] + childV.getHeight());
if(rect.contains( event.getX(), event.getY())) {
childV.getParent()
.requestDisallowInterceptTouchEvent(false);
childV.onTouchEvent(event);
return true;
}
}
childV.getParent()
.requestDisallowInterceptTouchEvent(true);
return false;
}
});