Search in sources :

Example 6 with LayoutManager

use of android.support.v7.widget.RecyclerView.LayoutManager in project MultiType by drakeet.

the class BilibiliActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list);
    adapter = new MultiTypeAdapter();
    adapter.applyGlobalMultiTypePool();
    adapter.register(Post.class, new PostViewBinder());
    adapter.register(PostList.class, new HorizontalPostsViewBinder());
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
    final GridLayoutManager layoutManager = new GridLayoutManager(this, SPAN_COUNT);
    SpanSizeLookup spanSizeLookup = new SpanSizeLookup() {

        @Override
        public int getSpanSize(int position) {
            Object item = items.get(position);
            return (item instanceof PostList || item instanceof Category) ? SPAN_COUNT : 1;
        }
    };
    layoutManager.setSpanSizeLookup(spanSizeLookup);
    recyclerView.setLayoutManager(layoutManager);
    int space = getResources().getDimensionPixelSize(R.dimen.normal_space);
    recyclerView.addItemDecoration(new PostItemDecoration(space, spanSizeLookup));
    recyclerView.setAdapter(adapter);
    JsonData data = new JsonData();
    items = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        /* You also could use Category as your CategoryItemContent directly */
        items.add(data.category0);
        items.add(data.postArray[0]);
        items.add(data.postArray[1]);
        items.add(data.postArray[2]);
        items.add(data.postArray[3]);
        items.add(data.postArray[0]);
        items.add(data.postArray[1]);
        items.add(new PostList(data.postList));
    }
    adapter.setItems(items);
    adapter.notifyDataSetChanged();
}
Also used : Category(me.drakeet.multitype.sample.common.Category) SpanSizeLookup(android.support.v7.widget.GridLayoutManager.SpanSizeLookup) GridLayoutManager(android.support.v7.widget.GridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) MultiTypeAdapter(me.drakeet.multitype.MultiTypeAdapter)

Example 7 with LayoutManager

use of android.support.v7.widget.RecyclerView.LayoutManager in project glide by bumptech.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ImageView giphyLogoView = (ImageView) findViewById(R.id.giphy_logo_view);
    Glide.with(this).load(R.raw.large_giphy_logo).into(giphyLogoView);
    RecyclerView gifList = (RecyclerView) findViewById(R.id.gif_list);
    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    gifList.setLayoutManager(layoutManager);
    RequestBuilder<Drawable> gifItemRequest = Glide.with(this).asDrawable();
    ViewPreloadSizeProvider<Api.GifResult> preloadSizeProvider = new ViewPreloadSizeProvider<>();
    adapter = new GifAdapter(this, gifItemRequest, preloadSizeProvider);
    gifList.setAdapter(adapter);
    RecyclerViewPreloader<Api.GifResult> preloader = new RecyclerViewPreloader<>(Glide.with(this), adapter, preloadSizeProvider, 4);
    gifList.addOnScrollListener(preloader);
}
Also used : RecyclerViewPreloader(com.bumptech.glide.integration.recyclerview.RecyclerViewPreloader) Drawable(android.graphics.drawable.Drawable) RecyclerView(android.support.v7.widget.RecyclerView) ImageView(android.widget.ImageView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ViewPreloadSizeProvider(com.bumptech.glide.util.ViewPreloadSizeProvider)

Example 8 with LayoutManager

use of android.support.v7.widget.RecyclerView.LayoutManager in project RecyclerRefreshLayout by dinuscxj.

the class HeaderViewRecyclerAdapter method adjustSpanSize.

public void adjustSpanSize(RecyclerView recycler) {
    if (recycler.getLayoutManager() instanceof GridLayoutManager) {
        final GridLayoutManager layoutManager = (GridLayoutManager) recycler.getLayoutManager();
        layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

            @Override
            public int getSpanSize(int position) {
                boolean isHeaderOrFooter = isHeaderPosition(position) || isFooterPosition(position);
                return isHeaderOrFooter ? layoutManager.getSpanCount() : 1;
            }
        });
    }
    if (recycler.getLayoutManager() instanceof StaggeredGridLayoutManager) {
        this.mIsStaggeredGrid = true;
    }
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager)

Example 9 with LayoutManager

use of android.support.v7.widget.RecyclerView.LayoutManager in project FlexibleAdapter by davideas.

the class FragmentStaggeredLayout method initializeRecyclerView.

@SuppressWarnings({ "ConstantConditions", "NullableProblems" })
private void initializeRecyclerView(Bundle savedInstanceState) {
    // Initialize Adapter and RecyclerView
    // ExampleAdapter makes use of stableIds, I strongly suggest to implement 'item.hashCode()'
    mAdapter = new FlexibleAdapter<>(DatabaseService.getInstance().getDatabaseList(), getActivity());
    mRecyclerView = (RecyclerView) getView().findViewById(R.id.recycler_view);
    // Customize the speed of the smooth scroll.
    // NOTE: Every time you change this value you MUST recreate the LayoutManager instance
    // and to assign it again to the RecyclerView!
    TopSnappedSmoothScroller.MILLISECONDS_PER_INCH = 33f;
    mRecyclerView.setLayoutManager(createNewStaggeredGridLayoutManager());
    // This value is restored to 100f (default) right here, because it is used in the
    // constructor by Android. If we don't change it now, others LayoutManager will be
    // impacted too by the above modification!
    TopSnappedSmoothScroller.MILLISECONDS_PER_INCH = 100f;
    mRecyclerView.setAdapter(mAdapter);
    //Size of RV will not change
    mRecyclerView.setHasFixedSize(true);
    // NOTE: Use default item animator 'canReuseUpdatedViewHolder()' will return true if
    // a Payload is provided. FlexibleAdapter is actually sending Payloads onItemChange.
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    // Experimenting NEW features (v5.0.0)
    //Show Headers at startUp!
    mAdapter.setDisplayHeadersAtStartUp(true).setNotifyMoveOfFilteredItems(true).setPermanentDelete(//Default=true
    true).setOnlyEntryAnimation(true);
    SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) getView().findViewById(R.id.swipeRefreshLayout);
    swipeRefreshLayout.setEnabled(true);
    mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, SelectableAdapter.MODE_IDLE);
    // Add 1 Scrollable Header
    mAdapter.addScrollableHeader(new ScrollableUseCaseItem(getString(R.string.staggered_use_case_title), getString(R.string.staggered_use_case_description)));
}
Also used : ScrollableUseCaseItem(eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 10 with LayoutManager

use of android.support.v7.widget.RecyclerView.LayoutManager in project FlexibleAdapter by davideas.

the class ExampleAdapter method showLayoutInfo.

/*
	 * HEADER VIEW
	 * This method shows how to add Header View as it was for ListView.
	 * Same Header item is enqueued for removal with a delay.
	 * The view is represented by a custom Item type to better represent any dynamic content.
	 */
public void showLayoutInfo(boolean scrollToPosition) {
    if (!hasSearchText()) {
        final ScrollableLayoutItem item = new ScrollableLayoutItem("LAY-L");
        if (mRecyclerView.getLayoutManager() instanceof StaggeredGridLayoutManager) {
            item.setId("LAY-S");
            item.setTitle(mRecyclerView.getContext().getString(R.string.staggered_layout));
        } else if (mRecyclerView.getLayoutManager() instanceof GridLayoutManager) {
            item.setId("LAY-G");
            item.setTitle(mRecyclerView.getContext().getString(R.string.grid_layout));
        } else {
            item.setTitle(mRecyclerView.getContext().getString(R.string.linear_layout));
        }
        item.setSubtitle(mRecyclerView.getContext().getString(R.string.columns, String.valueOf(Utils.getSpanCount(mRecyclerView.getLayoutManager()))));
        // NOTE: If you have to change at runtime the LayoutManager AND add
        // Scrollable Headers, consider to add them in post, using a delay >= 0
        // otherwise scroll animations on all items will not start correctly.
        addScrollableHeaderWithDelay(item, 1200L, scrollToPosition);
        removeScrollableHeaderWithDelay(item, 4000L);
    }
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) ScrollableLayoutItem(eu.davidea.samples.flexibleadapter.items.ScrollableLayoutItem) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)182 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)170 View (android.view.View)132 GridLayoutManager (android.support.v7.widget.GridLayoutManager)69 TextView (android.widget.TextView)60 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)44 ImageView (android.widget.ImageView)41 Bundle (android.os.Bundle)19 Nullable (android.support.annotation.Nullable)18 ViewGroup (android.view.ViewGroup)17 ArrayList (java.util.ArrayList)17 Intent (android.content.Intent)16 Toolbar (android.support.v7.widget.Toolbar)15 BindView (butterknife.BindView)15 Context (android.content.Context)14 Handler (android.os.Handler)13 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)13 DataSnapshot (com.google.firebase.database.DataSnapshot)11 DatabaseError (com.google.firebase.database.DatabaseError)11 Drawable (android.graphics.drawable.Drawable)10