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:
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="false" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<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>
<ScrollView
android:id="@+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="100dp"
android:focusableInTouchMode="false" >
<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" />
</ScrollView>
And here is the Java code:
parentScrollView = (ScrollView) findViewById(R.id.scrollView1);
childScrollView = (ScrollView) findViewById(R.id.scrollView2);
parentScrollView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View p_v, MotionEvent p_event) {
childScrollView.getParent().requestDisallowInterceptTouchEvent(
false);
// We will have to follow above for all scrollable contents
return false;
}
});
childScrollView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View p_v, MotionEvent p_event) {
// this will disallow the touch request for parent scroll on
// touch of child view
p_v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});
// We will have to follow above for all child scrollable contents
What seems to happen is this: when I have text in the TextView it doesn't seem to let me scroll it at all. It just scrolls the parent. But when I have no text and I touch the child ScrollView it doesn't scroll the parent so I guess it's working then. But do you have any ideas why it doesn't work when I have text?
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.
check this link which shows that how to use two widget with scroll functionality in same activity. check this below code in that.
I'm almost sure it is impossible:
How android handles touch events:
Parent gets event and decides if it has to handle it or if it should let handle it to the child;
so,if a scrollview handles the touch, the one which handles it, is always the parent one
http://developer.android.com/training/gestures/viewgroup.html
personally i don't know if is there a way to understand what is touched behind the parent scrollview to see if it is another scrollview and let it handle the movement
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:
and the Java Code would be
you can not use two Scrollview inside Scrollview OS get confuse which one have to scroll so your activity hang so do not use like this
Here is a possible solution which works fine with ScrollView and ListView inside a ScrollView. ScrollView Inside ScrollView