We've all been advised against nesting views that contain a scrolling mechanism. However, in the latest Android release (5.0), the Phone app caught my attention with what seems to be a ListView
inside of a ScrollView
.
What really intrigued me was that the scrolling mechanism switched from the ScrollView
to the ListView
seamlessly.
Notice the content above the tabs is pushed out of view before the actual ListView
begins scrolling.
I've tried duplicating this myself, but ended up unsuccessful. Here is the basic approach I was taking...
With a single, continuous touch event (no lifting of the finger) ...
As user scrolls, the ListView
slowly covers up the ImageView
. Once the ImageView
is 100% covered and the ListView
takes up the entire screen, the ListView
begins to scroll.
I'm currently listening to touch events on the ListView
and if the top has been reached, call requestDisallowInterceptTouchEvent
on the ListView
, i.e.
@Override
public boolean onTouch(View v, MotionEvent event) {
if (listViewAtTop) {
v.requestDisallowInterceptTouchEvent(true);
} else {
v.requestDisallowInterceptTouchEvent(false);
}
return false;
}
The switching scrolling context works, only if you lift your finger and continue scrolling.
Is there a different approach that will achieve the desired effect?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…