Search in sources :

Example 21 with LayoutManager

use of android.support.v7.widget.RecyclerView.LayoutManager in project fresco by facebook.

the class DraweeRecyclerViewFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
    GridLayoutManager layoutManager = new GridLayoutManager(getContext(), SPAN_COUNT);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(new SimpleAdapter(createDummyData()));
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView)

Example 22 with LayoutManager

use of android.support.v7.widget.RecyclerView.LayoutManager in project MaterialViewPager by florent37.

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 23 with LayoutManager

use of android.support.v7.widget.RecyclerView.LayoutManager in project RecyclerView-FlexibleDivider by yqritc.

the class FlexibleDividerDecoration method getGroupIndex.

/**
     * Returns a group index for GridLayoutManager.
     * for LinearLayoutManager, always returns position.
     *
     * @param position current view position to draw divider
     * @param parent   RecyclerView
     * @return group index of items
     */
private int getGroupIndex(int position, RecyclerView parent) {
    if (parent.getLayoutManager() instanceof GridLayoutManager) {
        GridLayoutManager layoutManager = (GridLayoutManager) parent.getLayoutManager();
        GridLayoutManager.SpanSizeLookup spanSizeLookup = layoutManager.getSpanSizeLookup();
        int spanCount = layoutManager.getSpanCount();
        return spanSizeLookup.getSpanGroupIndex(position, spanCount);
    }
    return position;
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) Paint(android.graphics.Paint)

Example 24 with LayoutManager

use of android.support.v7.widget.RecyclerView.LayoutManager in project RecyclerView-FlexibleDivider by yqritc.

the class FlexibleDividerDecoration method wasDividerAlreadyDrawn.

/**
     * Determines whether divider was already drawn for the row the item is in,
     * effectively only makes sense for a grid
     *
     * @param position current view position to draw divider
     * @param parent   RecyclerView
     * @return true if the divider can be skipped as it is in the same row as the previous one.
     */
private boolean wasDividerAlreadyDrawn(int position, RecyclerView parent) {
    if (parent.getLayoutManager() instanceof GridLayoutManager) {
        GridLayoutManager layoutManager = (GridLayoutManager) parent.getLayoutManager();
        GridLayoutManager.SpanSizeLookup spanSizeLookup = layoutManager.getSpanSizeLookup();
        int spanCount = layoutManager.getSpanCount();
        return spanSizeLookup.getSpanIndex(position, spanCount) > 0;
    }
    return false;
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) Paint(android.graphics.Paint)

Example 25 with LayoutManager

use of android.support.v7.widget.RecyclerView.LayoutManager in project Android-SpinKit by ybq.

the class Page1Fragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.list);
    GridLayoutManager layoutManager = new GridLayoutManager(getContext(), 4);
    layoutManager.setOrientation(GridLayoutManager.VERTICAL);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(new RecyclerView.Adapter<Holder>() {

        @Override
        public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
            @SuppressLint("InflateParams") View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_list, null);
            return new Holder(view);
        }

        @Override
        public void onBindViewHolder(Holder holder, int position) {
            holder.bind(position);
        }

        @Override
        public int getItemCount() {
            return Style.values().length;
        }
    });
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) ViewGroup(android.view.ViewGroup) RecyclerView(android.support.v7.widget.RecyclerView) SpinKitView(com.github.ybq.android.spinkit.SpinKitView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) SuppressLint(android.annotation.SuppressLint)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)205 RecyclerView (android.support.v7.widget.RecyclerView)202 View (android.view.View)151 GridLayoutManager (android.support.v7.widget.GridLayoutManager)73 TextView (android.widget.TextView)66 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)47 ImageView (android.widget.ImageView)44 Bundle (android.os.Bundle)24 Nullable (android.support.annotation.Nullable)24 BindView (butterknife.BindView)22 ArrayList (java.util.ArrayList)21 ViewGroup (android.view.ViewGroup)20 Context (android.content.Context)17 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)16 Intent (android.content.Intent)15 Handler (android.os.Handler)15 Toolbar (android.support.v7.widget.Toolbar)15 List (java.util.List)12 Point (android.graphics.Point)10 Drawable (android.graphics.drawable.Drawable)10