use of android.support.v7.widget.StaggeredGridLayoutManager in project SmoothRefreshLayout by dkzwm.
the class ScrollCompat method canAutoRefresh.
public static boolean canAutoRefresh(View view) {
if (view instanceof AbsListView) {
AbsListView listView = (AbsListView) view;
final int lastVisiblePosition = listView.getLastVisiblePosition();
final Adapter adapter = listView.getAdapter();
return adapter != null && lastVisiblePosition == 0;
} else {
try {
if (view instanceof RecyclerView) {
RecyclerView recyclerView = (RecyclerView) view;
RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
if (manager == null)
return false;
int firstVisiblePosition = -1;
if (manager instanceof LinearLayoutManager) {
LinearLayoutManager linearManager = ((LinearLayoutManager) manager);
firstVisiblePosition = linearManager.findFirstVisibleItemPosition();
} else if (manager instanceof StaggeredGridLayoutManager) {
StaggeredGridLayoutManager gridLayoutManager = (StaggeredGridLayoutManager) manager;
int[] firstPositions = new int[gridLayoutManager.getSpanCount()];
gridLayoutManager.findFirstVisibleItemPositions(firstPositions);
firstVisiblePosition = firstPositions[0];
for (int value : firstPositions) {
if (value == 0) {
firstVisiblePosition = 0;
break;
}
}
}
RecyclerView.Adapter adapter = recyclerView.getAdapter();
return adapter != null && firstVisiblePosition == 0;
}
} catch (NoClassDefFoundError e) {
e.printStackTrace();
}
return false;
}
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project android-advancedrecyclerview by h6ah4i.
the class DraggableStaggeredGridExampleFragment method onViewCreated.
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// noinspection ConstantConditions
mRecyclerView = getView().findViewById(R.id.recycler_view);
mLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
// drag & drop manager
mRecyclerViewDragDropManager = new RecyclerViewDragDropManager();
mRecyclerViewDragDropManager.setDraggingItemShadowDrawable((NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z3));
// Start dragging after long press
mRecyclerViewDragDropManager.setInitiateOnLongPress(true);
mRecyclerViewDragDropManager.setInitiateOnMove(false);
mRecyclerViewDragDropManager.setLongPressTimeout(750);
// adapter
final DraggableStaggeredGridExampleAdapter myItemAdapter = new DraggableStaggeredGridExampleAdapter(getDataProvider());
mAdapter = myItemAdapter;
// wrap for dragging
mWrappedAdapter = mRecyclerViewDragDropManager.createWrappedAdapter(myItemAdapter);
final GeneralItemAnimator animator = new DraggableItemAnimator();
mRecyclerView.setLayoutManager(mLayoutManager);
// requires *wrapped* adapter
mRecyclerView.setAdapter(mWrappedAdapter);
mRecyclerView.setItemAnimator(animator);
mRecyclerView.setHasFixedSize(false);
// noinspection StatementWithEmptyBody
if (supportsViewElevation()) {
// Lollipop or later has native drop shadow feature. ItemShadowDecorator is not required.
} else {
mRecyclerView.addItemDecoration(new ItemShadowDecorator((NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z1)));
}
mRecyclerViewDragDropManager.attachRecyclerView(mRecyclerView);
// for debugging
// animator.setDebug(true);
// animator.setMoveDuration(2000);
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project xRecyclerViewF by Dsiner.
the class XRecyclerView method onScrollStateChanged.
@Override
public void onScrollStateChanged(int state) {
super.onScrollStateChanged(state);
if (state == RecyclerView.SCROLL_STATE_IDLE && listener != null && !isLoadingData && canLoadMore) {
LayoutManager layoutManager = getLayoutManager();
int lastVisibleItemPosition;
if (layoutManager instanceof GridLayoutManager) {
lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
int[] into = new int[((StaggeredGridLayoutManager) layoutManager).getSpanCount()];
((StaggeredGridLayoutManager) layoutManager).findLastVisibleItemPositions(into);
lastVisibleItemPosition = findMax(into);
} else {
lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
}
if (layoutManager.getChildCount() > 0 && lastVisibleItemPosition >= layoutManager.getItemCount() - 1 && layoutManager.getItemCount() > layoutManager.getChildCount() && !isNoMore && !isLoadMoreError && refreshHeader.getState() < ListState.STATE_REFRESHING) {
loadMore();
}
}
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project BaseRecyclerViewAdapter by donghan0912.
the class StaggeredFragment method onViewCreated.
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
SwipeRefreshLayout refreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swip_refresh);
refreshLayout.setEnabled(false);
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
StaggeredGridLayoutManager manager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
recyclerView.setLayoutManager(manager);
for (int i = 0; i < 20; i++) {
WQ wq = new WQ(getRandomHeight(), getDrawable());
list.add(new FourthItem(wq));
}
final BaseRecyclerViewAdapter adapter = new BaseRecyclerViewAdapter(list);
recyclerView.setAdapter(adapter);
adapter.addHeader(new SimpleItem(R.layout.layout_staggered_head) {
@Override
public void onBindViewHolder(BaseViewHolder holder, int position) {
StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams();
p.setFullSpan(true);
}
});
// 设置加载更多布局,并占满整行
adapter.setExtraItem(new SimpleItem(R.layout.layout_loadmore) {
@Override
public void onBindViewHolder(BaseViewHolder holder, int position) {
StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams();
p.setFullSpan(true);
}
});
recyclerView.addOnScrollListener(new EndlessRecyclerOnScrollListener() {
@Override
public void onLoadMore() {
if (!loadMore) {
return;
}
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
List<FourthItem> list2 = new ArrayList<>();
for (int i = 0; i < 21; i++) {
WQ wq = new WQ(getRandomHeight(), getDrawable());
list2.add(new FourthItem(wq));
}
list.addAll(list2);
if (list.size() > 70) {
adapter.setExtraItem(new SimpleItem(R.layout.layout_loadmore_complete) {
@Override
public void onBindViewHolder(BaseViewHolder holder, int position) {
StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams();
p.setFullSpan(true);
}
});
loadMore = false;
}
adapter.addData(list2);
}
}, 3000);
}
}, 3000);
}
});
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project GomoTest by suReZj.
the class MainActivity method initView.
private void initView() {
toolbar = (Toolbar) findViewById(R.id.activity_main_toolbar);
toolbar.setTitleTextColor(getResources().getColor(R.color.white));
setSupportActionBar(toolbar);
recyclerView = (RecyclerView) findViewById(R.id.activity_main_recyclerView);
layoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
recyclerView.setLayoutManager(layoutManager);
adapter = new main_recycle_adapter(list, MainActivity.this);
recyclerView.setAdapter(adapter);
pathList = DataSupport.findAll(ImagePath.class);
setImage(page);
springView = (SpringView) findViewById(R.id.activity_main_frame);
springView.setFooter(new DefaultFooter(MainActivity.this));
// list.add("http://7xi8d6.com1.z0.glb.clouddn.com/2017-01-20-030332.jpg");
// list.add("http://7xi8d6.com1.z0.glb.clouddn.com/2017-02-27-tumblr_om1aowIoKa1qbw5qso1_540.jpg");
}
Aggregations