我正在使用Android App,我的需求是RelativeLayout的子项,它是ScrollView的子项,当RelativeLayout的子项在滚动时达到顶部时我怎么得到?
我的代码OnScrollChnnged是
final LinearLayout shareAndFuirteLayOut = (LinearLayout) findViewById(R.id.shareAndFuirteLayOut);
final ScrollView mainScrollView = (ScrollView) findViewById(R.id.mainScrollView);
final ViewTreeObserver.OnScrollChangedListener onScrollChangedListener = new ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onScrollChanged() {
}
};
mainScrollView.setOnTouchListener(new View.OnTouchListener() {
private ViewTreeObserver observer;
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (observer == null) {
observer = mainScrollView.getViewTreeObserver();
observer.addOnScrollChangedListener(onScrollChangedListener);
} else if (!observer.isAlive()) {
observer.removeOnScrollChangedListener(onScrollChangedListener);
observer = mainScrollView.getViewTreeObserver();
observer.addOnScrollChangedListener(onScrollChangedListener);
}
return false;
}
});
答案 0 :(得分:0)
详细介绍@Nanoc注释,代码将按
if (nestedScrollView.getScrollY() > View.getY()) {
Log.d(TAG, "View visible");
stickyHeaderLayout.setVisibility(View.VISIBLE);
} else {
stickyHeaderLayout.setVisibility(View.GONE);
}