我有一个嵌套的子scrollview,设置为禁用滚动,直到父scrollview完成向上滚动。设置childScrollView.setNestedScrollingEnabled(true)
最初起作用,并在父完全向上滚动后重新启用ResponsiveScrollView parentScroll = (ResponsiveScrollView) findViewById(R.id.parentScroll);
final ScrollView childScroll = (ScrollView) findViewById(R.id.childScroll);
childScroll.setNestedScrollingEnabled(false); // disabled by default
parentScroll.setOnEndScrollListener(new PriorityNestedScrollView.OnEndScrollListener() {
@Override
public void onUpEndScroll() {
Log.i(TAG, "scrolling up has ended"); // successfully fires
childScroll.setNestedScrollingEnabled(true); // working...
}
@Override
public void onDownEndScroll() {
Log.i(TAG, "scrolling down has ended"); // successfully fires
childScroll.setNestedScrollingEnabled(false); // not working...
}
});
。但是,虽然这是有效的,但我希望在父项滚动到底部之后再次禁用嵌套的scrollview,但它不起作用。有什么想法吗?
MainActivity(摘要):
@Override
protected void onScrollChanged(int x, int y, int oldX, int oldY) {
super.onScrollChanged(x, y, oldX, oldY);
// scroll up ended
if (y >= END) {
if (onEndScrollListener != null) {
onEndScrollListener.onUpEndScroll();
}
}
// scroll down ended
if (y <= START) {
if (onEndScrollListener != null) {
onEndScrollListener.onDownEndScroll();
}
}
}
ResponsiveScrollView(摘要):
<div>
答案 0 :(得分:0)
这是我如何实现这一目标的。我拦截嵌套的滚动触摸事件,直到父级到达顶部。
ResponsiveScrollView:
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (isEnableScrolling()) {
return super.onInterceptTouchEvent(ev);
} else {
return true;
}
}
...
boolean enableScrolling = false // disabled by default
public boolean isEnableScrolling() {
return enableScrolling;
}
public void setEnableScrolling(boolean enableScrolling) {
this.enableScrolling = enableScrolling;
}
MainActivity:
@Override
public void onUpEndScroll() {
Log.i(TAG, "scrolling up has ended");
parentScroll.setEnableScrolling(true); // enable scrolling
}
@Override
public void onDownEndScroll() {
Log.i(TAG, "scrolling down has ended");
parentScroll.setEnableScrolling(false); // disable scrolling
}