use of android.support.v7.widget.StaggeredGridLayoutManager in project baseAdapter by hongyangAndroid.
the class RecyclerViewActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recyclerview);
initDatas();
mRecyclerView = (RecyclerView) findViewById(R.id.id_recyclerview);
// mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));
// mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
mRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL_LIST));
mAdapter = new CommonAdapter<String>(this, R.layout.item_list, mDatas) {
@Override
protected void convert(ViewHolder holder, String s, int position) {
holder.setText(R.id.id_item_list_title, s + " : " + holder.getAdapterPosition() + " , " + holder.getLayoutPosition());
}
};
initHeaderAndFooter();
// initEmptyView();
mLoadMoreWrapper = new LoadMoreWrapper(mHeaderAndFooterWrapper);
mLoadMoreWrapper.setLoadMoreView(R.layout.default_loading);
mLoadMoreWrapper.setOnLoadMoreListener(new LoadMoreWrapper.OnLoadMoreListener() {
@Override
public void onLoadMoreRequested() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 10; i++) {
mDatas.add("Add:" + i);
}
mLoadMoreWrapper.notifyDataSetChanged();
}
}, 3000);
}
});
mRecyclerView.setAdapter(mLoadMoreWrapper);
mAdapter.setOnItemClickListener(new CommonAdapter.OnItemClickListener() {
@Override
public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
Toast.makeText(RecyclerViewActivity.this, "pos = " + position, Toast.LENGTH_SHORT).show();
mAdapter.notifyItemRemoved(position);
}
@Override
public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
return false;
}
});
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project CloudReader by youlookwhat.
the class BookCustomFragment method onActivityCreated.
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
showContentView();
bindingView.srlBook.setColorSchemeColors(CommonUtils.getColor(R.color.colorTheme));
bindingView.srlBook.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
DebugUtil.error("-----onRefresh");
// listTag= Arrays.asList(BookApiUtils.getApiTag(position));
// String tag=BookApiUtils.getRandomTAG(listTag);
// doubanBookPresenter.searchBookByTag(BookReadingFragment.this,tag,false);
bindingView.srlBook.postDelayed(new Runnable() {
@Override
public void run() {
mStart = 0;
loadCustomData();
}
}, 1000);
}
});
// mBookAdapter = new BookAdapter(getActivity());
// mLayoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
mLayoutManager = new GridLayoutManager(getActivity(), 3);
bindingView.xrvBook.setLayoutManager(mLayoutManager);
// bindingView.xrvBook.setAdapter(mBookAdapter);
scrollRecycleView();
// 准备就绪
mIsPrepared = true;
/**
* 因为启动时先走loadData()再走onActivityCreated,
* 所以此处要额外调用load(),不然最初不会加载内容
*/
loadData();
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project CloudReader by youlookwhat.
the class WelfareFragment method setAdapter.
private void setAdapter(GankIoDataBean gankIoDataBean) {
// mWelfareAdapter = new WelfareAdapter();
mWelfareAdapter.addAll(gankIoDataBean.getResults());
//构造器中,第一个参数表示列数或者行数,第二个参数表示滑动方向,瀑布流
bindingView.xrvWelfare.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
bindingView.xrvWelfare.setAdapter(mWelfareAdapter);
mWelfareAdapter.notifyDataSetChanged();
mWelfareAdapter.setOnItemClickListener(new OnItemClickListener<GankIoDataBean.ResultBean>() {
@Override
public void onClick(GankIoDataBean.ResultBean resultsBean, int position) {
DebugUtil.error("-----" + imgList.toString());
DebugUtil.error("----imgList.size(): " + imgList.size());
Bundle bundle = new Bundle();
// 2,大图显示当前页数,1,头像,不显示页数
bundle.putInt("selet", 2);
//第几张
bundle.putInt("code", position);
bundle.putStringArrayList("imageuri", imgList);
Intent intent = new Intent(getContext(), ViewBigImageActivity.class);
intent.putExtras(bundle);
getContext().startActivity(intent);
}
});
// 显示成功后就不是第一次了,不再刷新
isFirst = false;
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project EasyRecyclerView by Jude95.
the class DividerDecoration method onDrawOver.
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
if (parent.getAdapter() == null) {
return;
}
int orientation = 0;
int headerCount = 0, footerCount = 0, dataCount;
if (parent.getAdapter() instanceof RecyclerArrayAdapter) {
headerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getHeaderCount();
footerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getFooterCount();
dataCount = ((RecyclerArrayAdapter) parent.getAdapter()).getCount();
} else {
dataCount = parent.getAdapter().getItemCount();
}
int dataStartPosition = headerCount;
int dataEndPosition = headerCount + dataCount;
RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
if (layoutManager instanceof StaggeredGridLayoutManager) {
orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation();
} else if (layoutManager instanceof GridLayoutManager) {
orientation = ((GridLayoutManager) layoutManager).getOrientation();
} else if (layoutManager instanceof LinearLayoutManager) {
orientation = ((LinearLayoutManager) layoutManager).getOrientation();
}
int start, end;
if (orientation == OrientationHelper.VERTICAL) {
start = parent.getPaddingLeft() + mPaddingLeft;
end = parent.getWidth() - parent.getPaddingRight() - mPaddingRight;
} else {
start = parent.getPaddingTop() + mPaddingLeft;
end = parent.getHeight() - parent.getPaddingBottom() - mPaddingRight;
}
int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = parent.getChildAt(i);
int position = parent.getChildAdapterPosition(child);
if (//数据项除了最后一项
position >= dataStartPosition && position < dataEndPosition - 1 || //数据项最后一项
(position == dataEndPosition - 1 && mDrawLastItem) || //header&footer且可绘制
(!(position >= dataStartPosition && position < dataEndPosition) && mDrawHeaderFooter)) {
if (orientation == OrientationHelper.VERTICAL) {
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
int top = child.getBottom() + params.bottomMargin;
int bottom = top + mHeight;
mColorDrawable.setBounds(start, top, end, bottom);
mColorDrawable.draw(c);
} else {
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
int left = child.getRight() + params.rightMargin;
int right = left + mHeight;
mColorDrawable.setBounds(left, start, right, end);
mColorDrawable.draw(c);
}
}
}
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project BaseRecyclerViewAdapterHelper by CymChad.
the class BaseQuickAdapter method disableLoadMoreIfNotFullPage.
/**
* check if full page after {@link #setNewData(List)}, if full, it will enable load more again.
*
* @param recyclerView your recyclerView
* @see #setNewData(List)
*/
public void disableLoadMoreIfNotFullPage(RecyclerView recyclerView) {
if (recyclerView == null)
return;
RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
if (manager == null)
return;
if (manager instanceof LinearLayoutManager) {
final LinearLayoutManager linearLayoutManager = (LinearLayoutManager) manager;
recyclerView.postDelayed(new Runnable() {
@Override
public void run() {
if ((linearLayoutManager.findLastCompletelyVisibleItemPosition() + 1) != getItemCount()) {
setEnableLoadMore(true);
}
}
}, 50);
} else if (manager instanceof StaggeredGridLayoutManager) {
final StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) manager;
recyclerView.postDelayed(new Runnable() {
@Override
public void run() {
final int[] positions = new int[staggeredGridLayoutManager.getSpanCount()];
staggeredGridLayoutManager.findLastCompletelyVisibleItemPositions(positions);
int pos = getTheBiggestNumber(positions) + 1;
if (pos != getItemCount()) {
setEnableLoadMore(true);
}
}
}, 50);
}
}
Aggregations