Search in sources :

Example 71 with StaggeredGridLayoutManager

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();
                }
            }
        }
    });
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 72 with StaggeredGridLayoutManager

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();
}
Also used : SimpleRecyleViewAdapter(com.litingzhe.justandroid.ui.listandGridView.adapter.SimpleRecyleViewAdapter) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) DividerGridItemDecoration(com.litingzhe.justandroid.ui.listandGridView.recyleDivider.DividerGridItemDecoration) BindView(butterknife.BindView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 73 with StaggeredGridLayoutManager

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()));
}
Also used : StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager)

Aggregations

StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)71 RecyclerView (android.support.v7.widget.RecyclerView)47 View (android.view.View)32 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)30 GridLayoutManager (android.support.v7.widget.GridLayoutManager)22 Handler (android.os.Handler)7 TextView (android.widget.TextView)7 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)6 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)5 ViewGroup (android.view.ViewGroup)5 AbsListView (android.widget.AbsListView)5 ScrollView (android.widget.ScrollView)5 BindView (butterknife.BindView)5 Intent (android.content.Intent)4 WebView (android.webkit.WebView)4 ArrayList (java.util.ArrayList)4 Bundle (android.os.Bundle)3 Nullable (android.support.annotation.Nullable)3 MenuItem (android.view.MenuItem)3 RefreshListenerAdapter (com.lcodecore.tkrefreshlayout.RefreshListenerAdapter)3