use of android.support.v7.widget.StaggeredGridLayoutManager in project BGARefreshLayout-Android by bingoogolapple.
the class BGARefreshScrollingUtil method isRecyclerViewToTop.
public static boolean isRecyclerViewToTop(RecyclerView recyclerView) {
if (recyclerView != null) {
RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
if (manager == null) {
return true;
}
if (manager.getItemCount() == 0) {
return true;
}
if (manager instanceof LinearLayoutManager) {
LinearLayoutManager layoutManager = (LinearLayoutManager) manager;
int firstChildTop = 0;
if (recyclerView.getChildCount() > 0) {
// 处理item高度超过一屏幕时的情况
View firstVisibleChild = recyclerView.getChildAt(0);
if (firstVisibleChild != null && firstVisibleChild.getMeasuredHeight() >= recyclerView.getMeasuredHeight()) {
if (android.os.Build.VERSION.SDK_INT < 14) {
return !(ViewCompat.canScrollVertically(recyclerView, -1) || recyclerView.getScrollY() > 0);
} else {
return !ViewCompat.canScrollVertically(recyclerView, -1);
}
}
// 如果RecyclerView的子控件数量不为0,获取第一个子控件的top
// 解决item的topMargin不为0时不能触发下拉刷新
View firstChild = recyclerView.getChildAt(0);
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) firstChild.getLayoutParams();
firstChildTop = firstChild.getTop() - layoutParams.topMargin - getRecyclerViewItemTopInset(layoutParams) - recyclerView.getPaddingTop();
}
if (layoutManager.findFirstCompletelyVisibleItemPosition() < 1 && firstChildTop == 0) {
return true;
}
} else if (manager instanceof StaggeredGridLayoutManager) {
StaggeredGridLayoutManager layoutManager = (StaggeredGridLayoutManager) manager;
int[] out = layoutManager.findFirstCompletelyVisibleItemPositions(null);
if (out[0] < 1) {
return true;
}
}
}
return false;
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project baseAdapter by hongyangAndroid.
the class RecyclerViewActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
switch(id) {
case R.id.action_linear:
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
break;
case R.id.action_grid:
mRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));
break;
case R.id.action_staggered:
mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
break;
}
mRecyclerView.setAdapter(mLoadMoreWrapper);
return super.onOptionsItemSelected(item);
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project SuperRecyclerView by Malinskiy.
the class SuperRecyclerView method caseStaggeredGrid.
private int caseStaggeredGrid(RecyclerView.LayoutManager layoutManager) {
StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
if (lastScrollPositions == null)
lastScrollPositions = new int[staggeredGridLayoutManager.getSpanCount()];
staggeredGridLayoutManager.findLastVisibleItemPositions(lastScrollPositions);
return findMax(lastScrollPositions);
}
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 BaseRecyclerViewAdapterHelper by CymChad.
the class SectionUseActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_section_uer);
setBackBtn();
setTitle("Section Use");
mRecyclerView = (RecyclerView) findViewById(R.id.rv_list);
mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
mData = DataServer.getSampleData();
SectionAdapter sectionAdapter = new SectionAdapter(R.layout.item_section_content, R.layout.def_section_head, mData);
mRecyclerView.addOnItemTouchListener(new OnItemClickListener() {
@Override
public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
MySection mySection = mData.get(position);
if (mySection.isHeader)
Toast.makeText(SectionUseActivity.this, mySection.header, Toast.LENGTH_LONG).show();
else
Toast.makeText(SectionUseActivity.this, mySection.t.getName(), Toast.LENGTH_LONG).show();
}
@Override
public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
Toast.makeText(SectionUseActivity.this, "onItemChildClick" + position, Toast.LENGTH_LONG).show();
}
});
mRecyclerView.setAdapter(sectionAdapter);
}
Aggregations