use of android.support.v7.widget.StaggeredGridLayoutManager in project bdcodehelper by boredream.
the class LoadMoreAdapter method setScrollListener.
/**
* 设置滚动监听, 判断当列表滚动到底部时, 触发加载更多回调
*/
private void setScrollListener() {
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManager instanceof StaggeredGridLayoutManager) {
StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
int pastVisibleItems = -1;
int visibleItemCount = staggeredGridLayoutManager.getChildCount();
int totalItemCount = staggeredGridLayoutManager.getItemCount();
int[] firstVisibleItems = null;
firstVisibleItems = staggeredGridLayoutManager.findFirstVisibleItemPositions(firstVisibleItems);
if (firstVisibleItems != null && firstVisibleItems.length > 0) {
pastVisibleItems = firstVisibleItems[0];
}
if (visibleItemCount + pastVisibleItems >= totalItemCount) {
triggerLoadMore();
}
} else if (layoutManager instanceof LinearLayoutManager) {
// GridLayoutManager 是 LinearLayoutManager 的子类, 也符合这个条件
LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
int visibleItemCount = linearLayoutManager.getChildCount();
int totalItemCount = linearLayoutManager.getItemCount();
int firstVisibleItemPosition = linearLayoutManager.findFirstVisibleItemPosition();
if (visibleItemCount + firstVisibleItemPosition >= totalItemCount) {
triggerLoadMore();
}
}
}
});
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project JustAndroid by chinaltz.
the class SimpleRecyleViewActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_single_recyclerview);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
navToolBarBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
toolbarTitle.setText("RecycleView简单使用");
initData();
mAdapter = new SimpleRecyleViewAdapter(this, mDatas);
mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(4, StaggeredGridLayoutManager.VERTICAL));
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.addItemDecoration(new DividerGridItemDecoration(this));
// 设置item动画
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
initEvent();
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project JustAndroid by chinaltz.
the class StaggeredActivity method initView.
private void initView() {
recyclerview = (RecyclerView) findViewById(R.id.staggered_recycler);
mLayoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
recyclerview.setLayoutManager(mLayoutManager);
swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.staggered_swipe_refresh);
swipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary, R.color.colorPrimaryDark, R.color.colorAccent);
swipeRefreshLayout.setProgressViewOffset(false, 0, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, getResources().getDisplayMetrics()));
}
Aggregations