use of androidx.recyclerview.widget.GridLayoutManager in project SherlockAdapter by EvilBT.
the class MultiItemActivity method initView.
private void initView() {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mGridLayoutManager = new GridLayoutManager(this, 3);
mStaggeredGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
final SwipeRefreshLayout refreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh);
mRecyclerView = (RecyclerView) findViewById(R.id.list);
mRecyclerView.setLayoutManager(mGridLayoutManager);
mIsGrid = true;
mAdapter = new MyMultiAdapter();
mRecyclerView.setAdapter(mAdapter);
mAdapter.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(@NonNull View view, final int adapterPosition) {
new AlertDialog.Builder(MultiItemActivity.this).setTitle("是否删除第" + adapterPosition + "项").setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mAdapter.removeData(adapterPosition);
}
}).setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).create().show();
return true;
}
});
mData = new ArrayList<>();
initGridData();
refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
refreshLayout.postDelayed(new Runnable() {
@Override
public void run() {
mAdapter.setData(mData);
refreshLayout.setRefreshing(false);
}
}, 500);
}
});
}
use of androidx.recyclerview.widget.GridLayoutManager in project SherlockAdapter by EvilBT.
the class BaseAdapter method onAttachedToRecyclerView.
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
mRecyclerView = recyclerView;
RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
if (manager == null || !(manager instanceof GridLayoutManager))
return;
final GridLayoutManager gridLayoutManager = (GridLayoutManager) manager;
gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (mShowErrorView) {
if (mAlwaysShowHead && position < getHeadSize()) {
// 显示头部
if (mHeadLayoutAndSpanStates[position * 3 + 2] > 0) {
int spanCount = gridLayoutManager.getSpanCount();
return mHeadLayoutAndSpanStates[position * 3 + 2] > spanCount ? spanCount : mHeadLayoutAndSpanStates[position * 3 + 2];
}
if (mHeadLayoutAndSpanStates[position * 3 + 1] == 0) {
return 1;
}
return gridLayoutManager.getSpanCount();
}
if (mAlwaysShowFoot) {
int index = position - (mAlwaysShowHead ? (getHeadSize() + 1) : 1);
if (index >= 0 && index < getFootSize()) {
// 显示尾部
if (mFootLayoutAndSpanStates[index * 3 + 2] > 0) {
int spanCount = gridLayoutManager.getSpanCount();
return mFootLayoutAndSpanStates[index * 3 + 2] > spanCount ? spanCount : mFootLayoutAndSpanStates[index * 3 + 2];
}
if (mFootLayoutAndSpanStates[index * 3 + 1] == 0) {
return 1;
}
return gridLayoutManager.getSpanCount();
}
}
// 当数据异常时,Error界面都FullSpan
return gridLayoutManager.getSpanCount();
}
if (mData.isEmpty()) {
if (mAlwaysShowHead && position < getHeadSize()) {
// 显示头部
if (mHeadLayoutAndSpanStates[position * 3 + 2] > 0) {
int spanCount = gridLayoutManager.getSpanCount();
return mHeadLayoutAndSpanStates[position * 3 + 2] > spanCount ? spanCount : mHeadLayoutAndSpanStates[position * 3 + 2];
}
if (mHeadLayoutAndSpanStates[position * 3 + 1] == 0) {
return 1;
}
return gridLayoutManager.getSpanCount();
}
if (mAlwaysShowFoot) {
int index = position - (mAlwaysShowHead ? (getHeadSize() + 1) : 1);
if (index >= 0 && index < getFootSize()) {
// 显示尾部
if (mFootLayoutAndSpanStates[index * 3 + 2] > 0) {
int spanCount = gridLayoutManager.getSpanCount();
return mFootLayoutAndSpanStates[index * 3 + 2] > spanCount ? spanCount : mFootLayoutAndSpanStates[index * 3 + 2];
}
if (mFootLayoutAndSpanStates[index * 3 + 1] == 0) {
return 1;
}
return gridLayoutManager.getSpanCount();
}
}
// 当数据为空时,Empty界面都FullSpan
return gridLayoutManager.getSpanCount();
}
if (position < getHeadSize()) {
// 显示头部
if (mHeadLayoutAndSpanStates[position * 3 + 2] > 0) {
int spanCount = gridLayoutManager.getSpanCount();
return mHeadLayoutAndSpanStates[position * 3 + 2] > spanCount ? spanCount : mHeadLayoutAndSpanStates[position * 3 + 2];
}
if (mHeadLayoutAndSpanStates[position * 3 + 1] == 0) {
return 1;
}
return gridLayoutManager.getSpanCount();
}
int index = position - (getHeadSize() + mData.size());
if (index >= 0 && index < getFootSize()) {
// 显示尾部
if (mFootLayoutAndSpanStates[index * 3 + 2] > 0) {
int spanCount = gridLayoutManager.getSpanCount();
return mFootLayoutAndSpanStates[index * 3 + 2] > spanCount ? spanCount : mFootLayoutAndSpanStates[index * 3 + 2];
}
if (mFootLayoutAndSpanStates[index * 3 + 1] == 0) {
return 1;
}
return gridLayoutManager.getSpanCount();
}
if (index >= 0) {
// 显示加载更多
return gridLayoutManager.getSpanCount();
}
final T data = getData(position);
if (data != null && data instanceof IMultiItem) {
int spanSize = ((IMultiItem) data).getSpanSize();
return spanSize <= 0 ? 1 : spanSize > gridLayoutManager.getSpanCount() ? gridLayoutManager.getSpanCount() : spanSize;
}
return 1;
}
});
}
use of androidx.recyclerview.widget.GridLayoutManager in project mopub-android-mediation by mopub.
the class NativeRecyclerViewFragment method toggleRecyclerLayout.
void toggleRecyclerLayout() {
if (mLayoutType == LayoutType.LINEAR) {
mLayoutType = LayoutType.GRID;
mRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2));
} else {
mLayoutType = LayoutType.LINEAR;
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
}
}
use of androidx.recyclerview.widget.GridLayoutManager in project BaseProject by fly803.
the class AutoFitRecyclerView method init.
private void init() {
int mode = (int) SharedPreferencesUtils.getInstance().get("sp_key_switch_mode", 0);
if (mode == MODE_LIST) {
mSpanCount = 1;
} else {
mSpanCount = 2;
}
manager = new GridLayoutManager(getContext(), mSpanCount);
setLayoutManager(manager);
mChildrenHeights = new SparseIntArray();
}
use of androidx.recyclerview.widget.GridLayoutManager in project BaseProject by fly803.
the class GridRecyclerView method init.
private void init() {
int spanCount = 2;
GridLayoutManager manager = new GridLayoutManager(getContext(), spanCount);
setLayoutManager(manager);
}
Aggregations