use of android.support.v7.widget.StaggeredGridLayoutManager in project AndroidDevelop by 7449.
the class MRecyclerView method onScrolled.
@Override
public void onScrolled(int dx, int dy) {
super.onScrolled(dx, dy);
RecyclerView.LayoutManager layoutManager = getLayoutManager();
if (layoutManagerType == null) {
if (layoutManager instanceof GridLayoutManager) {
layoutManagerType = LAYOUT_MANAGER_TYPE.GRID;
} else if (layoutManager instanceof LinearLayoutManager) {
layoutManagerType = LAYOUT_MANAGER_TYPE.LINEAR;
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
layoutManagerType = LAYOUT_MANAGER_TYPE.STAGGERED_GRID;
} else {
throw new RuntimeException("Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
}
}
switch(layoutManagerType) {
case LINEAR:
lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
break;
case GRID:
lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
break;
case STAGGERED_GRID:
StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
if (lastPositions == null) {
lastPositions = new int[staggeredGridLayoutManager.getSpanCount()];
}
staggeredGridLayoutManager.findLastVisibleItemPositions(lastPositions);
lastVisibleItemPosition = findMax(lastPositions);
break;
}
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project AndroidDevelop by 7449.
the class RecyclerOnScrollListener method onScrolled.
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManagerType == null) {
if (layoutManager instanceof LinearLayoutManager) {
layoutManagerType = LAYOUT_MANAGER_TYPE.LINEAR;
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
layoutManagerType = LAYOUT_MANAGER_TYPE.STAGGERED_GRID;
} else {
throw new RuntimeException("Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
}
}
switch(layoutManagerType) {
case LINEAR:
lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
break;
case GRID:
lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
break;
case STAGGERED_GRID:
StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
if (lastPositions == null) {
lastPositions = new int[staggeredGridLayoutManager.getSpanCount()];
}
staggeredGridLayoutManager.findLastVisibleItemPositions(lastPositions);
lastVisibleItemPosition = findMax(lastPositions);
break;
}
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project AndroidDevelop by 7449.
the class StaggeredGridLayoutManagerActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
mDatas = new ArrayList<>();
initData(mDatas);
adapter = new MyAdapter(mDatas, recyclerView);
adapter.setLoadingListener(this);
adapter.setOnItemClickListener(this);
adapter.addHeader(getView(R.layout.header));
adapter.addFooter(getView(R.layout.footer));
recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
recyclerView.setAdapter(adapter);
View headerView = adapter.getHeaderView();
View footerView = adapter.getFooterView();
footerView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast("this is footer");
}
});
headerView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast("this is header");
}
});
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project BookReader by JustWayward.
the class DividerDecoration method onDrawOver.
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
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 EasyRecyclerView by Jude95.
the class StaggeredGridActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recyclerview);
recyclerView = (EasyRecyclerView) findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new StaggeredGridLayoutManager(4, StaggeredGridLayoutManager.VERTICAL));
recyclerView.setAdapter(adapter = new ImageAdapter(this));
GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 4);
gridLayoutManager.setSpanSizeLookup(adapter.obtainGridSpanSizeLookUp(4));
recyclerView.setLayoutManager(gridLayoutManager);
adapter.addHeader(new RecyclerArrayAdapter.ItemView() {
@Override
public View onCreateView(ViewGroup parent) {
RollPagerView header = new RollPagerView(StaggeredGridActivity.this);
header.setHintView(new ColorPointHintView(StaggeredGridActivity.this, Color.YELLOW, Color.GRAY));
header.setHintPadding(0, 0, 0, (int) Utils.convertDpToPixel(8, StaggeredGridActivity.this));
header.setPlayDelay(2000);
header.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) Utils.convertDpToPixel(200, StaggeredGridActivity.this)));
header.setAdapter(new BannerAdapter(StaggeredGridActivity.this));
return header;
}
@Override
public void onBindView(View headerView) {
}
});
SpaceDecoration itemDecoration = new SpaceDecoration((int) Utils.convertDpToPixel(8, this));
itemDecoration.setPaddingEdgeSide(true);
itemDecoration.setPaddingStart(true);
itemDecoration.setPaddingHeaderFooter(true);
recyclerView.addItemDecoration(itemDecoration);
adapter.setMore(R.layout.view_more, new RecyclerArrayAdapter.OnMoreListener() {
@Override
public void onMoreShow() {
addData();
}
@Override
public void onMoreClick() {
}
});
adapter.setNoMore(R.layout.view_nomore);
recyclerView.setRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
recyclerView.postDelayed(new Runnable() {
@Override
public void run() {
adapter.clear();
adapter.addAll(DataProvider.getPictures(0));
}
}, 1000);
}
});
addData();
}
Aggregations