Search in sources :

Example 36 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project SwipeRecyclerView by yanzhenjie.

the class SwipeRecyclerView method setLayoutManager.

@Override
public void setLayoutManager(LayoutManager layoutManager) {
    if (layoutManager instanceof GridLayoutManager) {
        final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
        final GridLayoutManager.SpanSizeLookup spanSizeLookupHolder = gridLayoutManager.getSpanSizeLookup();
        gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

            @Override
            public int getSpanSize(int position) {
                if (mAdapterWrapper.isHeader(position) || mAdapterWrapper.isFooter(position)) {
                    return gridLayoutManager.getSpanCount();
                }
                if (spanSizeLookupHolder != null) {
                    return spanSizeLookupHolder.getSpanSize(position - getHeaderCount());
                }
                return 1;
            }
        });
    }
    super.setLayoutManager(layoutManager);
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager)

Example 37 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project SwipeRecyclerView by yanzhenjie.

the class ItemTouchHelperCallback method getMovementFlags.

@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder targetViewHolder) {
    if (onItemMovementListener != null) {
        int dragFlags = onItemMovementListener.onDragFlags(recyclerView, targetViewHolder);
        int swipeFlags = onItemMovementListener.onSwipeFlags(recyclerView, targetViewHolder);
        return makeMovementFlags(dragFlags, swipeFlags);
    } else {
        RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
        if (layoutManager instanceof GridLayoutManager) {
            LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
            if (linearLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) {
                int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
                int swipeFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
                return makeMovementFlags(dragFlags, swipeFlags);
            } else {
                int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
                int swipeFlags = ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
                return makeMovementFlags(dragFlags, swipeFlags);
            }
        } else if (layoutManager instanceof LinearLayoutManager) {
            LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
            if (linearLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) {
                int dragFlags = ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
                int swipeFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
                return makeMovementFlags(dragFlags, swipeFlags);
            } else {
                int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
                int swipeFlags = ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
                return makeMovementFlags(dragFlags, swipeFlags);
            }
        }
    }
    return makeMovementFlags(0, 0);
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 38 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project SwipeRecyclerView by yanzhenjie.

the class AdapterWrapper method onAttachedToRecyclerView.

@Override
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
    mAdapter.onAttachedToRecyclerView(recyclerView);
    RecyclerView.LayoutManager lm = recyclerView.getLayoutManager();
    if (lm instanceof GridLayoutManager) {
        final GridLayoutManager glm = (GridLayoutManager) lm;
        final GridLayoutManager.SpanSizeLookup originLookup = glm.getSpanSizeLookup();
        glm.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

            @Override
            public int getSpanSize(int position) {
                if (isHeaderOrFooter(position))
                    return glm.getSpanCount();
                if (originLookup != null)
                    return originLookup.getSpanSize(position);
                return 1;
            }
        });
    }
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 39 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project SwipeRecyclerView by yanzhenjie.

the class DefaultActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_refresh_loadmore);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    assert actionBar != null;
    actionBar.setDisplayHomeAsUpEnabled(true);
    mRefreshLayout = findViewById(R.id.refresh_layout);
    // 刷新监听。
    mRefreshLayout.setOnRefreshListener(mRefreshListener);
    mRecyclerView = findViewById(R.id.recycler_view);
    mRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));
    mRecyclerView.addItemDecoration(new DefaultItemDecoration(ContextCompat.getColor(this, R.color.divider_color)));
    // RecyclerView Item点击监听。
    mRecyclerView.setOnItemClickListener(mItemClickListener);
    // 使用默认的加载更多的View。
    mRecyclerView.useDefaultLoadMore();
    // 加载更多的监听。
    mRecyclerView.setLoadMoreListener(mLoadMoreListener);
    mAdapter = new MainAdapter(this);
    mRecyclerView.setAdapter(mAdapter);
    // 请求服务器加载数据。
    loadData();
}
Also used : MainAdapter(com.yanzhenjie.recyclerview.sample.adapter.MainAdapter) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) DefaultItemDecoration(com.yanzhenjie.recyclerview.widget.DefaultItemDecoration) ActionBar(androidx.appcompat.app.ActionBar) Toolbar(androidx.appcompat.widget.Toolbar)

Example 40 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project epoxy by airbnb.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    EpoxyRecyclerView recyclerView = (EpoxyRecyclerView) findViewById(R.id.recycler_view);
    recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
    recyclerView.setController(controller);
    if (savedInstanceState != null) {
        carousels = savedInstanceState.getParcelableArrayList(CAROUSEL_DATA_KEY);
    }
    initTouch(recyclerView);
    updateController();
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) EpoxyRecyclerView(com.airbnb.epoxy.EpoxyRecyclerView)

Aggregations

GridLayoutManager (androidx.recyclerview.widget.GridLayoutManager)122 RecyclerView (androidx.recyclerview.widget.RecyclerView)63 View (android.view.View)45 TextView (android.widget.TextView)19 StaggeredGridLayoutManager (androidx.recyclerview.widget.StaggeredGridLayoutManager)16 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)13 ImageView (android.widget.ImageView)12 Nullable (androidx.annotation.Nullable)11 Toolbar (androidx.appcompat.widget.Toolbar)10 ViewGroup (android.view.ViewGroup)7 SmoothScrollGridLayoutManager (eu.davidea.flexibleadapter.common.SmoothScrollGridLayoutManager)7 SuppressLint (android.annotation.SuppressLint)6 Context (android.content.Context)6 ArrayList (java.util.ArrayList)6 NonNull (androidx.annotation.NonNull)5 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)5 List (java.util.List)5 RefreshingListenerAdapter (me.dkzwm.widget.srl.RefreshingListenerAdapter)5 Drawable (android.graphics.drawable.Drawable)4 Handler (android.os.Handler)3