Search in sources :

Example 1 with MaterialViewPagerAnimator

use of com.github.florent37.materialviewpager.MaterialViewPagerAnimator in project easy by MehdiBenmesa.

the class MaterialViewPagerHeaderDecorator method getItemOffsets.

@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView recyclerView, RecyclerView.State state) {
    final RecyclerView.ViewHolder holder = recyclerView.getChildViewHolder(view);
    final Context context = recyclerView.getContext();
    if (!registered) {
        MaterialViewPagerHelper.registerRecyclerView(context, recyclerView);
        registered = true;
    }
    int headerCells = 1;
    // don't work with stagged
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
        headerCells = gridLayoutManager.getSpanCount();
    }
    MaterialViewPagerAnimator animator = MaterialViewPagerHelper.getAnimator(context);
    if (animator != null) {
        if (holder.getAdapterPosition() < headerCells) {
            outRect.top = Math.round(Utils.dpToPx(animator.getHeaderHeight() + 10, context));
        }
    }
}
Also used : Context(android.content.Context) MaterialViewPagerAnimator(com.github.florent37.materialviewpager.MaterialViewPagerAnimator) GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView)

Example 2 with MaterialViewPagerAnimator

use of com.github.florent37.materialviewpager.MaterialViewPagerAnimator in project MaterialViewPager by florent37.

the class MaterialViewPagerHeaderDecorator method getItemOffsets.

@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView recyclerView, RecyclerView.State state) {
    final RecyclerView.ViewHolder holder = recyclerView.getChildViewHolder(view);
    final Context context = recyclerView.getContext();
    if (!registered) {
        MaterialViewPagerHelper.registerRecyclerView(context, recyclerView);
        registered = true;
    }
    int headerCells = 1;
    // don't work with stagged
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
        headerCells = gridLayoutManager.getSpanCount();
    }
    MaterialViewPagerAnimator animator = MaterialViewPagerHelper.getAnimator(context);
    if (animator != null) {
        if (holder.getAdapterPosition() < headerCells) {
            outRect.top = Math.round(Utils.dpToPx(animator.getHeaderHeight() + 10, context));
        }
    }
}
Also used : Context(android.content.Context) MaterialViewPagerAnimator(com.github.florent37.materialviewpager.MaterialViewPagerAnimator) GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

Context (android.content.Context)2 GridLayoutManager (android.support.v7.widget.GridLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)2 MaterialViewPagerAnimator (com.github.florent37.materialviewpager.MaterialViewPagerAnimator)2