问题描述
我有被设置为禁用滚动直到父滚动视图滚动完成了一个嵌套的子滚动视图。设置 childScrollView.setNestedScrollingEnabled(假)
开始工作,并重新启用 childScrollView.setNestedScrollingEnabled(真)
MainActivity(片段):
ResponsiveScrollView parentScroll =(ResponsiveScrollView)findViewById(R.id.parentScroll);最后滚动型childScroll =(滚动型)findViewById(R.id.childScroll);childScroll.setNestedScrollingEnabled(假); //默认情况下禁用parentScroll.setOnEndScrollListener(新PriorityNestedScrollView.OnEndScrollListener(){ @覆盖
公共无效onUpEndScroll(){
Log.i(TAG,向上滚动已经结束); //成功发射 childScroll.setNestedScrollingEnabled(真); //工作...
} @覆盖
公共无效onDownEndScroll(){
Log.i(TAG,向下滚动已经结束); //成功发射 childScroll.setNestedScrollingEnabled(假); //不工作...
}
});
ResponsiveScrollView(片段):
@覆盖
保护无效onScrollChanged(INT X,INT Y,诠释oldX,诠释oldY){
super.onScrollChanged(X,Y,oldX,oldY); //滚动结束
如果(Y> = END){
如果(onEndScrollListener!= NULL){
onEndScrollListener.onUpEndScroll();
}
} //向下滚动结束
如果(Y< = START){
如果(onEndScrollListener!= NULL){
onEndScrollListener.onDownEndScroll();
}
}
}
下面是我如何做到了这一点。我拦截嵌套的滚动触摸事件,直到父已达到了顶级。
ResponsiveScrollView:
@覆盖
公共布尔onInterceptTouchEvent(MotionEvent EV){
如果(isEnableScrolling()){
返回super.onInterceptTouchEvent(EV);
}其他{
返回true;
}
}...默认情况下禁用布尔enableScrolling = FALSE //公共布尔isEnableScrolling(){
返回enableScrolling;
}公共无效setEnableScrolling(布尔enableScrolling){
this.enableScrolling = enableScrolling;
}
MainActivity:
@覆盖
公共无效onUpEndScroll(){
Log.i(TAG,向上滚动已经结束); parentScroll.setEnableScrolling(真); //滚动启用
}@覆盖
公共无效onDownEndScroll(){
Log.i(TAG,向下滚动已经结束); parentScroll.setEnableScrolling(假); //禁用滚动
}
I have a nested child scrollview that is set to disable scrolling until the parent scrollview completes scrolling up. Setting the childScrollView.setNestedScrollingEnabled(false)
works initially, and is reenabled childScrollView.setNestedScrollingEnabled(true)
after the parent is scrolled up completely. However, while this is working, I want to again disable the nested scrollview after the parent is scrolled to the bottom, but it's not working. Any ideas?
MainActivity (snippet) :
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...
}
});
ResponsiveScrollView (snippet) :
@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();
}
}
}
Here's how I accomplished this. I intercept the nested scroll touch events until the parent has reached the top.
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
}
这篇关于Android的SetNestedScrollingEnabled不叫?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!