use of android.support.v7.widget.StaggeredGridLayoutManager in project BestPracticeApp by pop1234o.
the class RecyclerViewActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recycler_view);
RecyclerView recycer = (RecyclerView) findViewById(R.id.recycer);
// recycer.setLayoutManager(new LinearLayoutManager(this));
// recycer.setLayoutManager(new GridLayoutManager(this,3));
recycer.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
adapter = new RecyclerView.Adapter<ListHolder>() {
@Override
public ListHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.list_recycle, null);
view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
ListHolder listHolder = new ListHolder(view);
return listHolder;
}
@Override
public void onBindViewHolder(ListHolder holder, int position) {
holder.setData(position);
}
@Override
public int getItemCount() {
return 50;
}
};
recycer.setAdapter(adapter);
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new ListCallback());
itemTouchHelper.attachToRecyclerView(recycer);
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project AndroidNews by zhjohow.
the class PhotosFragment method initView.
@Override
public void initView() {
if (getArguments() != null) {
mPhotoType = getArguments().getString(AppConstant.PHOTO_TYPE);
}
adapter = new CommonRecycleViewAdapter<PhotoGirl>(getContext(), R.layout.item_photo) {
@Override
public void convert(ViewHolderHelper helper, final PhotoGirl photoGirl) {
ImageView imageView = helper.getView(R.id.iv_photo);
Glide.with(mContext).load(photoGirl.getThumbUrl()).diskCacheStrategy(DiskCacheStrategy.SOURCE).placeholder(R.drawable.ic_image_loading).error(R.drawable.ic_empty_picture).centerCrop().override(1090, 1090 * 3 / 4).crossFade().into(imageView);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PhotosDetailActivity.startAction(mContext, photoGirl.getThumbUrl());
}
});
}
};
irc.setAdapter(adapter);
irc.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
irc.setOnLoadMoreListener(this);
irc.setOnRefreshListener(this);
// fab.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// irc.smoothScrollToPosition(0);
// }
// });
mPresenter.getPhotosListDataRequest(mPhotoType, SIZE, mStartPage);
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project remusic by aa112901.
the class SwipeRefreshLayout method isChildScrollToBottom.
/**
* 是否滑动到底部
*
* @return
*/
public boolean isChildScrollToBottom() {
if (isChildScrollToTop()) {
return false;
}
if (mTarget instanceof RecyclerView) {
RecyclerView recyclerView = (RecyclerView) mTarget;
LayoutManager layoutManager = recyclerView.getLayoutManager();
int count = recyclerView.getAdapter().getItemCount();
if (layoutManager instanceof LinearLayoutManager && count > 0) {
LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
if (linearLayoutManager.findLastCompletelyVisibleItemPosition() == count - 1) {
return true;
}
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
int[] lastItems = new int[2];
staggeredGridLayoutManager.findLastCompletelyVisibleItemPositions(lastItems);
int lastItem = Math.max(lastItems[0], lastItems[1]);
if (lastItem == count - 1) {
return true;
}
}
return false;
} else if (mTarget instanceof AbsListView) {
final AbsListView absListView = (AbsListView) mTarget;
int count = absListView.getAdapter().getCount();
int fristPos = absListView.getFirstVisiblePosition();
if (fristPos == 0 && absListView.getChildAt(0).getTop() >= absListView.getPaddingTop()) {
return false;
}
int lastPos = absListView.getLastVisiblePosition();
if (lastPos > 0 && count > 0 && lastPos == count - 1) {
return true;
}
return false;
} else if (mTarget instanceof ScrollView) {
ScrollView scrollView = (ScrollView) mTarget;
View view = (View) scrollView.getChildAt(scrollView.getChildCount() - 1);
if (view != null) {
int diff = (view.getBottom() - (scrollView.getHeight() + scrollView.getScrollY()));
if (diff == 0) {
return true;
}
}
}
return false;
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project Collar by CodeZsx.
the class EndlessRecyclerViewOnScrollListener method onScrolled.
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManager != null) {
if (layoutManager instanceof LinearLayoutManager) {
layoutManagerType = LINEARLAYOUT;
} else if (layoutManager instanceof GridLayoutManager) {
layoutManagerType = GRIDLAYOUT;
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
layoutManagerType = STAGGEREDGRIDLAYOUT;
} else {
throw new RuntimeException("Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
}
}
switch(layoutManagerType) {
case LINEARLAYOUT:
lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
break;
case GRIDLAYOUT:
lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
break;
case STAGGEREDGRIDLAYOUT:
StaggeredGridLayoutManager staggeredGridLayoutManager = ((StaggeredGridLayoutManager) layoutManager);
if (lastPositions == null) {
lastPositions = new int[staggeredGridLayoutManager.getSpanCount()];
}
staggeredGridLayoutManager.findLastVisibleItemPositions(lastPositions);
lastVisibleItemPosition = lastPositions[0];
for (int value : lastPositions) {
lastVisibleItemPosition = value > lastVisibleItemPosition ? value : lastVisibleItemPosition;
}
break;
}
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project weiui by kuaifan.
the class RecylerOnBottomScrollListener 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;
}
}
Aggregations