You can create custom ScrollView and ListView and override
onInterceptTouchEvent(MotionEvent event)
like this:
@Override public boolean onInterceptTouchEvent(MotionEvent event) { View view = (View) getChildAt(getChildCount()-1); int diff = (view.getBottom()-(getHeight()+getScrollY())); if( event.getAction() == MotionEvent.ACTION_DOWN) { if (diff ==0) { return false; } } return super.onInterceptTouchEvent(event); }
Thus, each press of the ListView button, when you are at the bottom of the ScrollView , will go to the ListView .
This is just a sketch implementation, but I think you could start by doing the same to detect when you are at the top of the ListView
As a side note, I would try to simplify the implementation using only ListView with the current contents of you ScrollView added as a ListView title using listView.addHeaderView(scrollViewContent) . I donβt know if this fits your needs.
EDIT:
Detecting when to start scrolling ScrollView . Saving a ListView link to a ScrollView . When the user scrolls and the ListView is at the top, let the event be consumed by the ScrollView .
private void init(){ ViewConfiguration vc = ViewConfiguration.get(getContext()); mTouchSlop = vc.getScaledTouchSlop(); } @Override public boolean onInterceptTouchEvent(MotionEvent event) { final int action = MotionEventCompat.getActionMasked(event); switch (action) { case MotionEvent.ACTION_DOWN:{ yPrec = event.getY(); } case MotionEvent.ACTION_MOVE: { final float dy = event.getY() - yPrec; if (dy > mTouchSlop) { // Start scrolling! mIsScrolling = true; } break; } } if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { mIsScrolling = false; } // Calculate the scrolldiff View view = (View) getChildAt(getChildCount()-1); int diff = (view.getBottom()-(getHeight()+getScrollY())); if ((!mIsScrolling || !listViewReference.listIsAtTop()) && diff == 0) { if (event.getAction() == MotionEvent.ACTION_MOVE) { return false; } } return super.onInterceptTouchEvent(event); } @Override public boolean onTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { mIsScrolling = false; } return super.onTouchEvent(ev); } public void setListViewReference(MyListView listViewReference) { this.listViewReference = listViewReference; }
The listIsAtTop method in a ListView is as follows:
public boolean listIsAtTop() { if(getChildCount() == 0) return true; return (getChildAt(0).getTop() == 0 && getFirstVisiblePosition() ==0); }
GeorgeP
source share