use of android.support.v7.widget.StaggeredGridLayoutManager in project AndroidDevelop by 7449.
the class ImageFragment method initData.
@Override
protected void initData() {
if (!isPrepared || !isVisible || isLoad) {
return;
}
recyclerView.setLoadingData(this);
recyclerView.setHasFixedSize(true);
imageListPresenter = new ImagePresenterImpl(this);
swipeRefreshLayout.setOnRefreshListener(this);
recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
adapter = new ImageAdapter(new LinkedList<BaseModel>());
adapter.setOnItemClickListener(this);
recyclerView.setAdapter(adapter);
swipeRefreshLayout.post(new Runnable() {
@Override
public void run() {
onRefresh();
}
});
setLoad();
}
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 bdcodehelper by boredream.
the class LoadMoreAdapter method setScrollListener.
/**
* 设置滚动监听, 判断当列表滚动到底部时, 触发加载更多回调
*/
private void setScrollListener() {
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManager instanceof StaggeredGridLayoutManager) {
StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
int pastVisibleItems = -1;
int visibleItemCount = staggeredGridLayoutManager.getChildCount();
int totalItemCount = staggeredGridLayoutManager.getItemCount();
int[] firstVisibleItems = null;
firstVisibleItems = staggeredGridLayoutManager.findFirstVisibleItemPositions(firstVisibleItems);
if (firstVisibleItems != null && firstVisibleItems.length > 0) {
pastVisibleItems = firstVisibleItems[0];
}
if (visibleItemCount + pastVisibleItems >= totalItemCount) {
triggerLoadMore();
}
} else if (layoutManager instanceof LinearLayoutManager) {
// GridLayoutManager 是 LinearLayoutManager 的子类, 也符合这个条件
LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
int visibleItemCount = linearLayoutManager.getChildCount();
int totalItemCount = linearLayoutManager.getItemCount();
int firstVisibleItemPosition = linearLayoutManager.findFirstVisibleItemPosition();
if (visibleItemCount + firstVisibleItemPosition >= totalItemCount) {
triggerLoadMore();
}
}
}
});
}
Aggregations