我在滚动视图中保留了一个按钮,该按钮仅在向上滚动时才可见,而在向下滚动时(如在paytm中)应该不可见。这是片段内的简单滚动视图。
scrollBtn.setVisibility(View.GONE);
scrollView.setOnScrollChangeListener(new View.OnScrollChangeListener() {
@Override
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
scroll.setVisibility(View.VISIBLE);
}
});
scrollBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
scrollView.scrollTo(0, 0);
}
});
答案 0 :(得分:1)
这应该对您有帮助。
代码
scrollView.setOnScrollChangeListener(new View.OnScrollChangeListener() {
@Override
public void onScrollChange(View view, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
//Scrolling down
if(scrollY<oldScrollY){
scrollBtn.setVisibility(View.GONE);
}else{
scrollBtn.setVisibility(View.VISIBLE);
}
}
});
答案 1 :(得分:0)
检出此Detecting the scrolling direction in the adapter (up/down)和内部mIsScrollingUp = false;
使用您的代码隐藏所需的布局