Search in sources :

Example 31 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project EasyRecyclerView by Jude95.

the class DividerDecoration method onDraw.

public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    if (parent.getAdapter() == null) {
        return;
    }
    int orientation = 0;
    int headerCount = 0, footerCount = 0, dataCount;
    if (parent.getAdapter() instanceof RecyclerArrayAdapter) {
        headerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getHeaderCount();
        footerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getFooterCount();
        dataCount = ((RecyclerArrayAdapter) parent.getAdapter()).getCount();
    } else {
        dataCount = parent.getAdapter().getItemCount();
    }
    int dataStartPosition = headerCount;
    int dataEndPosition = headerCount + dataCount;
    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof StaggeredGridLayoutManager) {
        orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation();
    } else if (layoutManager instanceof GridLayoutManager) {
        orientation = ((GridLayoutManager) layoutManager).getOrientation();
    } else if (layoutManager instanceof LinearLayoutManager) {
        orientation = ((LinearLayoutManager) layoutManager).getOrientation();
    }
    int start, end;
    if (orientation == OrientationHelper.VERTICAL) {
        start = parent.getPaddingLeft() + mPaddingLeft;
        end = parent.getWidth() - parent.getPaddingRight() - mPaddingRight;
    } else {
        start = parent.getPaddingTop() + mPaddingLeft;
        end = parent.getHeight() - parent.getPaddingBottom() - mPaddingRight;
    }
    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = parent.getChildAt(i);
        int position = parent.getChildAdapterPosition(child);
        if (// 数据项除了最后一项
        position >= dataStartPosition && position < dataEndPosition - 1 || // 数据项最后一项
        (position == dataEndPosition - 1 && mDrawLastItem) || // header&footer且可绘制
        (!(position >= dataStartPosition && position < dataEndPosition) && mDrawHeaderFooter)) {
            if (orientation == OrientationHelper.VERTICAL) {
                RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
                int top = child.getBottom() + params.bottomMargin;
                int bottom = top + mHeight;
                mColorDrawable.setBounds(start, top, end, bottom);
                mColorDrawable.draw(c);
            } else {
                RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
                int left = child.getRight() + params.rightMargin;
                int right = left + mHeight;
                mColorDrawable.setBounds(left, start, right, end);
                mColorDrawable.draw(c);
            }
        }
    }
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) RecyclerArrayAdapter(com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter) RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 32 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project weex-example by KalicyZhou.

the class WXRecyclerViewOnScrollListener method onScrolled.

@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    IOnLoadMoreListener l;
    if ((l = listener.get()) != null) {
        l.onBeforeScroll(dx, dy);
    }
    //  int lastVisibleItemPosition = -1;
    if (layoutManagerType == null) {
        if (layoutManager instanceof LinearLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.LINEAR;
        } else if (layoutManager instanceof GridLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.GRID;
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.STAGGERED_GRID;
        } else {
            throw new RuntimeException("Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
        }
    }
    switch(layoutManagerType) {
        case LINEAR:
            lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
            listener.get().notifyAppearStateChange(((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition(), lastVisibleItemPosition, dx, dy);
            break;
        case GRID:
            lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
            break;
        case STAGGERED_GRID:
            StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
            if (lastPositions == null) {
                lastPositions = new int[staggeredGridLayoutManager.getSpanCount()];
            }
            staggeredGridLayoutManager.findLastVisibleItemPositions(lastPositions);
            lastVisibleItemPosition = findMax(lastPositions);
            break;
    }
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) 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 33 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project easy by MehdiBenmesa.

the class Utils method scrollTo.

public static void scrollTo(Object scroll, float yOffset) {
    if (scroll instanceof RecyclerView) {
        //RecyclerView.scrollTo : UnsupportedOperationException
        //Moved to the RecyclerView.LayoutManager.scrollToPositionWithOffset
        //Have to be instanceOf RecyclerView.LayoutManager to work (so work with RecyclerView.GridLayoutManager)
        final RecyclerView.LayoutManager layoutManager = ((RecyclerView) scroll).getLayoutManager();
        if (layoutManager instanceof LinearLayoutManager) {
            LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
            linearLayoutManager.scrollToPositionWithOffset(0, (int) -yOffset);
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
            staggeredGridLayoutManager.scrollToPositionWithOffset(0, (int) -yOffset);
        }
    } else if (scroll instanceof NestedScrollView) {
        ((NestedScrollView) scroll).scrollTo(0, (int) yOffset);
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) NestedScrollView(android.support.v4.widget.NestedScrollView)

Example 34 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project XRecyclerView by jianghejie.

the class StaggeredGridActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recyclerview);
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    mRecyclerView = (XRecyclerView) this.findViewById(R.id.recyclerview);
    StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(layoutManager);
    mRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);
    mRecyclerView.setLoadingMoreProgressStyle(ProgressStyle.BallRotate);
    mRecyclerView.setArrowImageView(R.drawable.iconfont_downgrey);
    View header = LayoutInflater.from(this).inflate(R.layout.recyclerview_header, (ViewGroup) findViewById(android.R.id.content), false);
    mRecyclerView.addHeaderView(header);
    mRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {

        @Override
        public void onRefresh() {
            refreshTime++;
            times = 0;
            new Handler().postDelayed(new Runnable() {

                public void run() {
                    listData.clear();
                    for (int i = 0; i < 25; i++) {
                        listData.add("item" + i + "after " + refreshTime + " times of refresh");
                    }
                    mAdapter.notifyDataSetChanged();
                    mRecyclerView.refreshComplete();
                }
            }, // refresh data here
            1000);
        }

        @Override
        public void onLoadMore() {
            if (times < 2) {
                new Handler().postDelayed(new Runnable() {

                    public void run() {
                        mRecyclerView.loadMoreComplete();
                        for (int i = 0; i < 25; i++) {
                            listData.add("item" + (i + listData.size()));
                        }
                        mRecyclerView.loadMoreComplete();
                        mAdapter.notifyDataSetChanged();
                    }
                }, 1000);
            } else {
                new Handler().postDelayed(new Runnable() {

                    public void run() {
                        for (int i = 0; i < 9; i++) {
                            listData.add("item" + (1 + listData.size()));
                        }
                        mRecyclerView.setNoMore(true);
                        mAdapter.notifyDataSetChanged();
                    }
                }, 1000);
            }
            times++;
        }
    });
    listData = new ArrayList<String>();
    for (int i = 0; i < 25; i++) {
        listData.add("item" + i);
    }
    mAdapter = new MyAdapter(listData);
    mRecyclerView.setAdapter(mAdapter);
}
Also used : XRecyclerView(com.jcodecraeer.xrecyclerview.XRecyclerView) Handler(android.os.Handler) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) XRecyclerView(com.jcodecraeer.xrecyclerview.XRecyclerView) View(android.view.View) Toolbar(android.support.v7.widget.Toolbar)

Example 35 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project twicalico by moko256.

the class BaseTweetListFragment method initializeRecyclerViewLayoutManager.

@Override
protected RecyclerView.LayoutManager initializeRecyclerViewLayoutManager() {
    WindowManager wm = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int count = (int) Math.ceil((double) // Picture area: (16 : 9) + Other content: (16 : 3)
    (size.x * 12) / (size.y * 16));
    if (count == 1) {
        LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
        layoutManager.setRecycleChildrenOnDetach(true);
        return layoutManager;
    } else {
        return new StaggeredGridLayoutManager(count, StaggeredGridLayoutManager.VERTICAL);
    }
}
Also used : StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) Point(android.graphics.Point) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Point(android.graphics.Point) WindowManager(android.view.WindowManager) Display(android.view.Display)

Aggregations

StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)78 RecyclerView (android.support.v7.widget.RecyclerView)52 View (android.view.View)37 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)32 GridLayoutManager (android.support.v7.widget.GridLayoutManager)26 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)9 Handler (android.os.Handler)7 Toolbar (android.support.v7.widget.Toolbar)7 TextView (android.widget.TextView)7 Nullable (android.support.annotation.Nullable)5 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 ArrayList (java.util.ArrayList)5 Intent (android.content.Intent)4 WebView (android.webkit.WebView)4 Bundle (android.os.Bundle)3 FloatingActionButton (android.support.design.widget.FloatingActionButton)3