Search in sources :

Example 6 with GridLayoutManager

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

the class MultiSelectActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_multi_select);
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
    final GridLayoutManager layoutManager = new GridLayoutManager(this, SPAN_COUNT);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

        @Override
        public int getSpanSize(int position) {
            return (items.get(position) instanceof Category) ? SPAN_COUNT : 1;
        }
    });
    selectedSet = new TreeSet<>();
    recyclerView.setLayoutManager(layoutManager);
    adapter = new MultiTypeAdapter();
    adapter.applyGlobalMultiTypePool();
    adapter.register(Square.class, new SquareViewBinder(selectedSet));
    loadData();
    assertAllRegistered(adapter, items);
    recyclerView.setAdapter(adapter);
    setupFAB();
}
Also used : Category(me.drakeet.multitype.sample.common.Category) GridLayoutManager(android.support.v7.widget.GridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) MultiTypeAdapter(me.drakeet.multitype.MultiTypeAdapter)

Example 7 with GridLayoutManager

use of android.support.v7.widget.GridLayoutManager 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 8 with GridLayoutManager

use of android.support.v7.widget.GridLayoutManager 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 GridLayoutManager

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

the class OverallAdapter method showLayoutInfo.

/*
	 * HEADER/FOOTER VIEW
	 * This method show how to add Header/Footer View as it was for ListView.
	 * The secret is the position! 0 for Header; itemCount for Footer ;-)
	 * The view is represented by a custom Item type to better represent any dynamic content.
	 */
public void showLayoutInfo(boolean scrollToPosition) {
    if (!hasSearchText()) {
        //Define Example View
        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(eu.davidea.flexibleadapter.utils.Utils.getSpanCount(mRecyclerView.getLayoutManager()))));
        addScrollableHeaderWithDelay(item, 500L, scrollToPosition);
        removeScrollableHeaderWithDelay(item, 3000L);
    }
}
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)

Example 10 with GridLayoutManager

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

the class FragmentEndlessScrolling method onPrepareOptionsMenu.

@Override
public void onPrepareOptionsMenu(Menu menu) {
    Log.v(TAG, "onPrepareOptionsMenu called!");
    MenuItem gridMenuItem = menu.findItem(R.id.action_list_type);
    if (mRecyclerView.getLayoutManager() instanceof GridLayoutManager) {
        gridMenuItem.setIcon(R.drawable.ic_view_agenda_white_24dp);
        gridMenuItem.setTitle(R.string.linear_layout);
    } else {
        gridMenuItem.setIcon(R.drawable.ic_view_grid_white_24dp);
        gridMenuItem.setTitle(R.string.grid_layout);
    }
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) SmoothScrollGridLayoutManager(eu.davidea.flexibleadapter.common.SmoothScrollGridLayoutManager) MenuItem(android.view.MenuItem)

Aggregations

GridLayoutManager (android.support.v7.widget.GridLayoutManager)264 RecyclerView (android.support.v7.widget.RecyclerView)118 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)68 View (android.view.View)60 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)38 TextView (android.widget.TextView)32 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)15 MaterialViewPagerHeaderDecorator (com.github.florent37.materialviewpager.header.MaterialViewPagerHeaderDecorator)14 BindView (butterknife.BindView)13 ArrayList (java.util.ArrayList)13 Handler (android.os.Handler)12 Toolbar (android.support.v7.widget.Toolbar)12 ImageView (android.widget.ImageView)12 Context (android.content.Context)11 Intent (android.content.Intent)11 Point (android.graphics.Point)9 Nullable (android.support.annotation.Nullable)9 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)9 SuppressLint (android.annotation.SuppressLint)8 AdapterView (android.widget.AdapterView)8