I saw someone had referenced this e-mail and thought I should share my solution
in case anyone else is attempting to make this work, it's actually quite easy.
All you need to do is override/add the following in your parent ScrollView to
prevent it from 'stealing' the gesture from another ScrollView or AdapterView
(list).
@Override
public boolean onInterceptTouchEvent(MotionEvent ev)
{
final int action = ev.getAction();
if (action == MotionEvent.ACTION_MOVE)
{
if (isScrollableChildAtPoint((int)ev.getX(), (int)ev.getY(), this))
return false;
}
return super.onInterceptTouchEvent(ev);
}
public static boolean isScrollableChildAtPoint(int x, int y, ViewGroup v)
{
Rect frame = new Rect();
x += v.getScrollX();
y += v.getScrollY();
for (int i = v.getChildCount() - 1; i >= 0; i--)
{
final View child = v.getChildAt(i);
child.getHitRect(frame);
if (frame.contains(x, y))
{
if (child instanceof FrameLayout || child instanceof
AdapterView<?>)
return true;
else if (child instanceof ViewGroup)
return isScrollableChildAtPoint(x, y, (ViewGroup)child);
}
}
return false;
}
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Romain Guy
> Sent: Wednesday, 15 September 2010 4:42 PM
> To: [email protected]
> Subject: Re: [android-developers] Scrolling broken in 2.2 ?
>
> Hi,
>
> You should never have a scrolling widget inside a scrolling widget;
> for instance a ListView inside a ScrollView. The behavior for such a
> setup is pretty much guaranteed to not work (and definitely not
> guaranteed to work.)
>
> On Tue, Sep 14, 2010 at 11:39 PM, Peter Carpenter
> <[email protected]> wrote:
> > My app builds up a custom screen as dictated to me via the users
> > 'application'. This means that I can end up in the situation where I have a
> > parent scrollview and somewhere down the heirachy I can have a listView or a
> > multiline TextView.
>
> > Both of these scenarios continue to work fine under 2.1, however are broken
> > in 2.2 (both device and emulator). The symptoms are that the child (list or
> > textview) is unable to scroll using touch gestures although they can be
> > scrolled using the keypad.
>
> > Has anyone else experienced this behaviour and/or have a work around?? It
> > appears that the onTouchEvent function in View has been changed
> > substantially but I am currently delving into the code...
>
> > Cheers,
>
> > Peter.
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
>
> --
> Romain Guy
> Android framework engineer
> [email protected]
>
> Note: please don't send private questions to me, as I don't have time
> to provide private support. All such questions should be posted on
> public forums, where I and others can see and answer them
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group
> athttp://groups.google.com/group/android-developers?hl=en
>
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en