Search in sources :

Example 71 with LayoutManager

use of android.support.v7.widget.RecyclerView.LayoutManager in project vlayout by alibaba.

the class BaseLayoutHelper method nextView.

/**
     * Retrieve next view and add it into layout, this is to make sure that view are added by order
     *
     * @param recycler    recycler generate views
     * @param layoutState current layout state
     * @param helper      helper to add views
     * @param result      chunk result to tell layoutManager whether layout process goes end
     * @return next view to render, null if no more view available
     */
@Nullable
public final View nextView(RecyclerView.Recycler recycler, LayoutStateWrapper layoutState, LayoutManagerHelper helper, LayoutChunkResult result) {
    View view = layoutState.next(recycler);
    if (view == null) {
        // no more items to layout.
        if (DEBUG && !layoutState.hasScrapList()) {
            throw new RuntimeException("received null view when unexpected");
        }
        // if there is no more views can be retrieved, this layout process is finished
        result.mFinished = true;
        return null;
    }
    helper.addChildView(layoutState, view);
    return view;
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) Nullable(android.support.annotation.Nullable)

Example 72 with LayoutManager

use of android.support.v7.widget.RecyclerView.LayoutManager in project vlayout by alibaba.

the class StaggeredGridLayoutHelper method hasGapsToFix.

/**
     * Checks for gaps if we've reached to the top of the list.
     * <p/>
     * Intermediate gaps created by full span items are tracked via mLaidOutInvalidFullSpan field.
     */
private View hasGapsToFix(VirtualLayoutManager layoutManager, final int position, final int alignLine) {
    View view = layoutManager.findViewByPosition(position);
    if (view == null)
        return null;
    BitSet mSpansToCheck = new BitSet(mNumLanes);
    mSpansToCheck.set(0, mNumLanes, true);
    for (Span span : mSpans) {
        if (span.mViews.size() != 0 && checkSpanForGap(span, layoutManager, alignLine)) {
            return layoutManager.getReverseLayout() ? span.mViews.get(span.mViews.size() - 1) : span.mViews.get(0);
        }
    }
    // everything looks good
    return null;
}
Also used : BitSet(java.util.BitSet) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 73 with LayoutManager

use of android.support.v7.widget.RecyclerView.LayoutManager in project RxImagePicker by qingmei2.

the class AlbumMediaAdapter method refreshSelection.

public void refreshSelection() {
    GridLayoutManager layoutManager = (GridLayoutManager) mRecyclerView.getLayoutManager();
    int first = layoutManager.findFirstVisibleItemPosition();
    int last = layoutManager.findLastVisibleItemPosition();
    if (first == -1 || last == -1) {
        return;
    }
    Cursor cursor = getCursor();
    for (int i = first; i <= last; i++) {
        RecyclerView.ViewHolder holder = mRecyclerView.findViewHolderForAdapterPosition(first);
        if (holder instanceof MediaViewHolder) {
            if (cursor.moveToPosition(i)) {
                setCheckStatus(Item.valueOf(cursor), ((MediaViewHolder) holder).mMediaGrid);
            }
        }
    }
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) Cursor(android.database.Cursor)

Example 74 with LayoutManager

use of android.support.v7.widget.RecyclerView.LayoutManager 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 75 with LayoutManager

use of android.support.v7.widget.RecyclerView.LayoutManager 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)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)430 RecyclerView (android.support.v7.widget.RecyclerView)371 View (android.view.View)261 GridLayoutManager (android.support.v7.widget.GridLayoutManager)128 TextView (android.widget.TextView)113 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)79 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)73 ImageView (android.widget.ImageView)71 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)47 Intent (android.content.Intent)46 ArrayList (java.util.ArrayList)43 Bundle (android.os.Bundle)37 Nullable (android.support.annotation.Nullable)33 Context (android.content.Context)29 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)28 BindView (butterknife.BindView)28 Toolbar (android.support.v7.widget.Toolbar)25 ViewGroup (android.view.ViewGroup)25 Handler (android.os.Handler)22 FloatingActionButton (android.support.design.widget.FloatingActionButton)21