Search in sources :

Example 86 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project SmoothRefreshLayout by dkzwm.

the class ScrollCompat method canAutoRefresh.

public static boolean canAutoRefresh(View view) {
    if (view instanceof AbsListView) {
        AbsListView listView = (AbsListView) view;
        final int lastVisiblePosition = listView.getLastVisiblePosition();
        final Adapter adapter = listView.getAdapter();
        return adapter != null && lastVisiblePosition == 0;
    } else {
        try {
            if (view instanceof RecyclerView) {
                RecyclerView recyclerView = (RecyclerView) view;
                RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
                if (manager == null)
                    return false;
                int firstVisiblePosition = -1;
                if (manager instanceof LinearLayoutManager) {
                    LinearLayoutManager linearManager = ((LinearLayoutManager) manager);
                    firstVisiblePosition = linearManager.findFirstVisibleItemPosition();
                } else if (manager instanceof StaggeredGridLayoutManager) {
                    StaggeredGridLayoutManager gridLayoutManager = (StaggeredGridLayoutManager) manager;
                    int[] firstPositions = new int[gridLayoutManager.getSpanCount()];
                    gridLayoutManager.findFirstVisibleItemPositions(firstPositions);
                    firstVisiblePosition = firstPositions[0];
                    for (int value : firstPositions) {
                        if (value == 0) {
                            firstVisiblePosition = 0;
                            break;
                        }
                    }
                }
                RecyclerView.Adapter adapter = recyclerView.getAdapter();
                return adapter != null && firstVisiblePosition == 0;
            }
        } catch (NoClassDefFoundError e) {
            e.printStackTrace();
        }
        return false;
    }
}
Also used : AbsListView(android.widget.AbsListView) Adapter(android.widget.Adapter) RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SuppressLint(android.annotation.SuppressLint)

Example 87 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project android-advancedrecyclerview by h6ah4i.

the class DraggableStaggeredGridExampleFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    // noinspection ConstantConditions
    mRecyclerView = getView().findViewById(R.id.recycler_view);
    mLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
    // drag & drop manager
    mRecyclerViewDragDropManager = new RecyclerViewDragDropManager();
    mRecyclerViewDragDropManager.setDraggingItemShadowDrawable((NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z3));
    // Start dragging after long press
    mRecyclerViewDragDropManager.setInitiateOnLongPress(true);
    mRecyclerViewDragDropManager.setInitiateOnMove(false);
    mRecyclerViewDragDropManager.setLongPressTimeout(750);
    // adapter
    final DraggableStaggeredGridExampleAdapter myItemAdapter = new DraggableStaggeredGridExampleAdapter(getDataProvider());
    mAdapter = myItemAdapter;
    // wrap for dragging
    mWrappedAdapter = mRecyclerViewDragDropManager.createWrappedAdapter(myItemAdapter);
    final GeneralItemAnimator animator = new DraggableItemAnimator();
    mRecyclerView.setLayoutManager(mLayoutManager);
    // requires *wrapped* adapter
    mRecyclerView.setAdapter(mWrappedAdapter);
    mRecyclerView.setItemAnimator(animator);
    mRecyclerView.setHasFixedSize(false);
    // noinspection StatementWithEmptyBody
    if (supportsViewElevation()) {
    // Lollipop or later has native drop shadow feature. ItemShadowDecorator is not required.
    } else {
        mRecyclerView.addItemDecoration(new ItemShadowDecorator((NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z1)));
    }
    mRecyclerViewDragDropManager.attachRecyclerView(mRecyclerView);
// for debugging
// animator.setDebug(true);
// animator.setMoveDuration(2000);
}
Also used : ItemShadowDecorator(com.h6ah4i.android.widget.advrecyclerview.decoration.ItemShadowDecorator) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) GeneralItemAnimator(com.h6ah4i.android.widget.advrecyclerview.animator.GeneralItemAnimator) DraggableItemAnimator(com.h6ah4i.android.widget.advrecyclerview.animator.DraggableItemAnimator) RecyclerViewDragDropManager(com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager) NinePatchDrawable(android.graphics.drawable.NinePatchDrawable)

Example 88 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project xRecyclerViewF by Dsiner.

the class XRecyclerView method onScrollStateChanged.

@Override
public void onScrollStateChanged(int state) {
    super.onScrollStateChanged(state);
    if (state == RecyclerView.SCROLL_STATE_IDLE && listener != null && !isLoadingData && canLoadMore) {
        LayoutManager layoutManager = getLayoutManager();
        int lastVisibleItemPosition;
        if (layoutManager instanceof GridLayoutManager) {
            lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            int[] into = new int[((StaggeredGridLayoutManager) layoutManager).getSpanCount()];
            ((StaggeredGridLayoutManager) layoutManager).findLastVisibleItemPositions(into);
            lastVisibleItemPosition = findMax(into);
        } else {
            lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
        }
        if (layoutManager.getChildCount() > 0 && lastVisibleItemPosition >= layoutManager.getItemCount() - 1 && layoutManager.getItemCount() > layoutManager.getChildCount() && !isNoMore && !isLoadMoreError && refreshHeader.getState() < ListState.STATE_REFRESHING) {
            loadMore();
        }
    }
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) GridLayoutManager(android.support.v7.widget.GridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 89 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project BaseRecyclerViewAdapter by donghan0912.

the class StaggeredFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    SwipeRefreshLayout refreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swip_refresh);
    refreshLayout.setEnabled(false);
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
    StaggeredGridLayoutManager manager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
    recyclerView.setLayoutManager(manager);
    for (int i = 0; i < 20; i++) {
        WQ wq = new WQ(getRandomHeight(), getDrawable());
        list.add(new FourthItem(wq));
    }
    final BaseRecyclerViewAdapter adapter = new BaseRecyclerViewAdapter(list);
    recyclerView.setAdapter(adapter);
    adapter.addHeader(new SimpleItem(R.layout.layout_staggered_head) {

        @Override
        public void onBindViewHolder(BaseViewHolder holder, int position) {
            StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams();
            p.setFullSpan(true);
        }
    });
    // 设置加载更多布局,并占满整行
    adapter.setExtraItem(new SimpleItem(R.layout.layout_loadmore) {

        @Override
        public void onBindViewHolder(BaseViewHolder holder, int position) {
            StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams();
            p.setFullSpan(true);
        }
    });
    recyclerView.addOnScrollListener(new EndlessRecyclerOnScrollListener() {

        @Override
        public void onLoadMore() {
            if (!loadMore) {
                return;
            }
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    new Handler().postDelayed(new Runnable() {

                        @Override
                        public void run() {
                            List<FourthItem> list2 = new ArrayList<>();
                            for (int i = 0; i < 21; i++) {
                                WQ wq = new WQ(getRandomHeight(), getDrawable());
                                list2.add(new FourthItem(wq));
                            }
                            list.addAll(list2);
                            if (list.size() > 70) {
                                adapter.setExtraItem(new SimpleItem(R.layout.layout_loadmore_complete) {

                                    @Override
                                    public void onBindViewHolder(BaseViewHolder holder, int position) {
                                        StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams();
                                        p.setFullSpan(true);
                                    }
                                });
                                loadMore = false;
                            }
                            adapter.addData(list2);
                        }
                    }, 3000);
                }
            }, 3000);
        }
    });
}
Also used : BaseViewHolder(com.hpu.baserecyclerviewadapter.BaseViewHolder) EndlessRecyclerOnScrollListener(com.hpu.baserecyclerviewadapter.EndlessRecyclerOnScrollListener) Handler(android.os.Handler) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) FourthItem(com.hpu.baserecyclerviewadapter.sample.multi.FourthItem) RecyclerView(android.support.v7.widget.RecyclerView) WQ(com.hpu.baserecyclerviewadapter.sample.bean.WQ) ArrayList(java.util.ArrayList) List(java.util.List) BaseRecyclerViewAdapter(com.hpu.baserecyclerviewadapter.BaseRecyclerViewAdapter) SimpleItem(com.hpu.baserecyclerviewadapter.SimpleItem)

Example 90 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project GomoTest by suReZj.

the class MainActivity method initView.

private void initView() {
    toolbar = (Toolbar) findViewById(R.id.activity_main_toolbar);
    toolbar.setTitleTextColor(getResources().getColor(R.color.white));
    setSupportActionBar(toolbar);
    recyclerView = (RecyclerView) findViewById(R.id.activity_main_recyclerView);
    layoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
    recyclerView.setLayoutManager(layoutManager);
    adapter = new main_recycle_adapter(list, MainActivity.this);
    recyclerView.setAdapter(adapter);
    pathList = DataSupport.findAll(ImagePath.class);
    setImage(page);
    springView = (SpringView) findViewById(R.id.activity_main_frame);
    springView.setFooter(new DefaultFooter(MainActivity.this));
// list.add("http://7xi8d6.com1.z0.glb.clouddn.com/2017-01-20-030332.jpg");
// list.add("http://7xi8d6.com1.z0.glb.clouddn.com/2017-02-27-tumblr_om1aowIoKa1qbw5qso1_540.jpg");
}
Also used : adapter.main_recycle_adapter(adapter.main_recycle_adapter) ImagePath(bean.ImagePath) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) DefaultFooter(com.liaoinstan.springview.container.DefaultFooter)

Aggregations

StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)125 RecyclerView (android.support.v7.widget.RecyclerView)76 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)62 View (android.view.View)50 GridLayoutManager (android.support.v7.widget.GridLayoutManager)38 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)11 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)10 TextView (android.widget.TextView)10 Handler (android.os.Handler)9 BindView (butterknife.BindView)9 Intent (android.content.Intent)8 Nullable (android.support.annotation.Nullable)8 AbsListView (android.widget.AbsListView)8 ArrayList (java.util.ArrayList)8 ViewGroup (android.view.ViewGroup)6 WebView (android.webkit.WebView)6 ScrollView (android.widget.ScrollView)6 List (java.util.List)5 SuppressLint (android.annotation.SuppressLint)4 Point (android.graphics.Point)4