use of android.support.v7.widget.StaggeredGridLayoutManager in project EasyRecyclerView by Jude95.
the class DividerDecoration method onDraw.
public void onDraw(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 weex-example by KalicyZhou.
the class WXRecyclerViewOnScrollListener method onScrolled.
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
IOnLoadMoreListener l;
if ((l = listener.get()) != null) {
l.onBeforeScroll(dx, dy);
}
// int lastVisibleItemPosition = -1;
if (layoutManagerType == null) {
if (layoutManager instanceof LinearLayoutManager) {
layoutManagerType = LAYOUT_MANAGER_TYPE.LINEAR;
} else if (layoutManager instanceof GridLayoutManager) {
layoutManagerType = LAYOUT_MANAGER_TYPE.GRID;
} 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();
listener.get().notifyAppearStateChange(((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition(), lastVisibleItemPosition, dx, dy);
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 easy by MehdiBenmesa.
the class Utils method scrollTo.
public static void scrollTo(Object scroll, float yOffset) {
if (scroll instanceof RecyclerView) {
//RecyclerView.scrollTo : UnsupportedOperationException
//Moved to the RecyclerView.LayoutManager.scrollToPositionWithOffset
//Have to be instanceOf RecyclerView.LayoutManager to work (so work with RecyclerView.GridLayoutManager)
final RecyclerView.LayoutManager layoutManager = ((RecyclerView) scroll).getLayoutManager();
if (layoutManager instanceof LinearLayoutManager) {
LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
linearLayoutManager.scrollToPositionWithOffset(0, (int) -yOffset);
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
staggeredGridLayoutManager.scrollToPositionWithOffset(0, (int) -yOffset);
}
} else if (scroll instanceof NestedScrollView) {
((NestedScrollView) scroll).scrollTo(0, (int) yOffset);
}
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project XRecyclerView by jianghejie.
the class StaggeredGridActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recyclerview);
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mRecyclerView = (XRecyclerView) this.findViewById(R.id.recyclerview);
StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);
mRecyclerView.setLoadingMoreProgressStyle(ProgressStyle.BallRotate);
mRecyclerView.setArrowImageView(R.drawable.iconfont_downgrey);
View header = LayoutInflater.from(this).inflate(R.layout.recyclerview_header, (ViewGroup) findViewById(android.R.id.content), false);
mRecyclerView.addHeaderView(header);
mRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
@Override
public void onRefresh() {
refreshTime++;
times = 0;
new Handler().postDelayed(new Runnable() {
public void run() {
listData.clear();
for (int i = 0; i < 25; i++) {
listData.add("item" + i + "after " + refreshTime + " times of refresh");
}
mAdapter.notifyDataSetChanged();
mRecyclerView.refreshComplete();
}
}, // refresh data here
1000);
}
@Override
public void onLoadMore() {
if (times < 2) {
new Handler().postDelayed(new Runnable() {
public void run() {
mRecyclerView.loadMoreComplete();
for (int i = 0; i < 25; i++) {
listData.add("item" + (i + listData.size()));
}
mRecyclerView.loadMoreComplete();
mAdapter.notifyDataSetChanged();
}
}, 1000);
} else {
new Handler().postDelayed(new Runnable() {
public void run() {
for (int i = 0; i < 9; i++) {
listData.add("item" + (1 + listData.size()));
}
mRecyclerView.setNoMore(true);
mAdapter.notifyDataSetChanged();
}
}, 1000);
}
times++;
}
});
listData = new ArrayList<String>();
for (int i = 0; i < 25; i++) {
listData.add("item" + i);
}
mAdapter = new MyAdapter(listData);
mRecyclerView.setAdapter(mAdapter);
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project twicalico by moko256.
the class BaseTweetListFragment method initializeRecyclerViewLayoutManager.
@Override
protected RecyclerView.LayoutManager initializeRecyclerViewLayoutManager() {
WindowManager wm = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int count = (int) Math.ceil((double) // Picture area: (16 : 9) + Other content: (16 : 3)
(size.x * 12) / (size.y * 16));
if (count == 1) {
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
layoutManager.setRecycleChildrenOnDetach(true);
return layoutManager;
} else {
return new StaggeredGridLayoutManager(count, StaggeredGridLayoutManager.VERTICAL);
}
}
Aggregations