Search in sources :

Example 36 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 37 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 38 with LayoutManager

use of android.support.v7.widget.RecyclerView.LayoutManager in project philm by chrisbanes.

the class MovieDetailFragment method populateUi.

private void populateUi() {
    if (mMovie == null) {
        return;
    }
    if (mBackdropImageView != null) {
        if (mMovie.hasBackdropUrl()) {
            mBackdropImageView.loadBackdrop(mMovie);
        }
    }
    if (mCollapsingToolbarLayout != null) {
        mCollapsingToolbarLayout.setTitle(mMovie.getTitle());
    }
    mAdapter = new GroupAdapter();
    mAdapter.add(new TitleItem());
    mAdapter.add(new ButtonsItem());
    if (!TextUtils.isEmpty(mMovie.getOverview())) {
        mAdapter.add(new SummaryItem());
    }
    mAdapter.add(new RatingItem());
    mAdapter.add(new DetailsGroup());
    //
    //        if (!PhilmCollections.isEmpty(mMovie.getTrailers())) {
    //            mItems.add(DetailItemType.TRAILERS);
    //        }
    //
    //        if (!PhilmCollections.isEmpty(mMovie.getCast())) {
    //            mItems.add(DetailItemType.CAST);
    //        }
    //
    //        if (!PhilmCollections.isEmpty(mMovie.getCrew())) {
    //            mItems.add(DetailItemType.CREW);
    //        }
    //
    //        if (!PhilmCollections.isEmpty(mMovie.getRelated())) {
    //            mItems.add(DetailItemType.RELATED);
    //        }
    GridLayoutManager layoutManager = new GridLayoutManager(getContext(), mAdapter.getSpanCount());
    layoutManager.setSpanSizeLookup(mAdapter.getSpanSizeLookup());
    mRecyclerView.setLayoutManager(layoutManager);
    mRecyclerView.setAdapter(mAdapter);
}
Also used : GroupAdapter(com.genius.groupie.GroupAdapter) GridLayoutManager(android.support.v7.widget.GridLayoutManager)

Example 39 with LayoutManager

use of android.support.v7.widget.RecyclerView.LayoutManager in project MyDiary by erttyy8821.

the class ContactsActivity method initTopicAdapter.

private void initTopicAdapter() {
    //Init topic adapter
    layoutManager = new LinearLayoutManager(this);
    RecyclerView_contacts.setLayoutManager(layoutManager);
    RecyclerView_contacts.setHasFixedSize(true);
    contactsAdapter = new ContactsAdapter(ContactsActivity.this, contactsNamesList, topicId, this);
    RecyclerView_contacts.setAdapter(contactsAdapter);
}
Also used : LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 40 with LayoutManager

use of android.support.v7.widget.RecyclerView.LayoutManager in project baseAdapter by hongyangAndroid.

the class WrapperUtils method onAttachedToRecyclerView.

public static void onAttachedToRecyclerView(RecyclerView.Adapter innerAdapter, RecyclerView recyclerView, final SpanSizeCallback callback) {
    innerAdapter.onAttachedToRecyclerView(recyclerView);
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
        final GridLayoutManager.SpanSizeLookup spanSizeLookup = gridLayoutManager.getSpanSizeLookup();
        gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

            @Override
            public int getSpanSize(int position) {
                return callback.getSpanSize(gridLayoutManager, spanSizeLookup, position);
            }
        });
        gridLayoutManager.setSpanCount(gridLayoutManager.getSpanCount());
    }
}
Also used : 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)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