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);
}
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);
}
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;
}
});
}
}
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();
}
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();
}
Aggregations