我在我的应用程序中使用ObservableScrollView,使用带有viewpager recycleview的片段,现在工作正常。我想为这个scrollview实现Endless适配器。
他是我的主要活动:
public class MainActivity extends AppCompatActivity implements ObservableScrollViewCallbacks{
......
mPagerAdapter = new NavigationAdapter(getSupportFragmentManager());
mPager = (NonSwipeableViewPager) findViewById(R.id.pager);
mPager.setAdapter(mPagerAdapter);
// Padding for ViewPager must be set outside the ViewPager itself
// because with padding, EdgeEffect of ViewPager become strange.
final int tabHeight = getResources().getDimensionPixelSize(R.dimen.tab_height);
findViewById(R.id.pager_wrapper).setPadding(0, getActionBarSize() + tabHeight, 0, 0);
SlidingTabLayout slidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs);
slidingTabLayout.setCustomTabView(R.layout.tab_indicator, android.R.id.text1);
slidingTabLayout.setSelectedIndicatorColors(getResources().getColor(android.R.color.white));
slidingTabLayout.setDistributeEvenly(true);
slidingTabLayout.setViewPager(mPager);
ViewConfiguration vc = ViewConfiguration.get(this);
mSlop = vc.getScaledTouchSlop();
mInterceptionLayout = (TouchInterceptionFrameLayout) findViewById(R.id.container);
mInterceptionLayout.setScrollInterceptionListener(mInterceptionListener);
.......
}
private TouchInterceptionFrameLayout.TouchInterceptionListener mInterceptionListener = new TouchInterceptionFrameLayout.TouchInterceptionListener() {
@Override
public boolean shouldInterceptTouchEvent(MotionEvent ev, boolean moving, float diffX, float diffY) {
if (!mScrolled && mSlop < Math.abs(diffX) && Math.abs(diffY) < Math.abs(diffX)) {
// Horizontal scroll is maybe handled by ViewPager
return false;
}
Scrollable scrollable = getCurrentScrollable();
if (scrollable == null) {
mScrolled = false;
return false;
}
// If interceptionLayout can move, it should intercept.
// And once it begins to move, horizontal scroll shouldn't work any longer.
int toolbarHeight = mToolbarView.getHeight();
int translationY = (int) ViewHelper.getTranslationY(mInterceptionLayout);
boolean scrollingUp = 0 < diffY;
boolean scrollingDown = diffY < 0;
if (scrollingUp) {
if (translationY < 0) {
mScrolled = true;
mLastScrollState = ScrollState.UP;
return true;
}
} else if (scrollingDown) {
if (-toolbarHeight < translationY) {
mScrolled = true;
mLastScrollState = ScrollState.DOWN;
return true;
}
}
mScrolled = false;
return false;
}
@Override
public void onDownMotionEvent(MotionEvent ev) {
}
@Override
public void onMoveMotionEvent(MotionEvent ev, float diffX, float diffY) {
float translationY = ScrollUtils.getFloat(ViewHelper.getTranslationY(mInterceptionLayout) + diffY, -mToolbarView.getHeight(), 0);
ViewHelper.setTranslationY(mInterceptionLayout, translationY);
if (translationY < 0) {
DrawerLayout.LayoutParams lp = (DrawerLayout.LayoutParams) mInterceptionLayout.getLayoutParams();
lp.height = (int) (-translationY + getScreenHeight());
mInterceptionLayout.requestLayout();
}
}
@Override
public void onUpOrCancelMotionEvent(MotionEvent ev) {
mScrolled = false;
adjustToolbar(mLastScrollState);
}
};
我应该在哪里维护滚动结束并请求加载更多项目。任何人都可以帮助我。