本文整理汇总了Java中android.support.v7.widget.LinearLayoutManager.findFirstVisibleItemPosition方法的典型用法代码示例。如果您正苦于以下问题:Java LinearLayoutManager.findFirstVisibleItemPosition方法的具体用法?Java LinearLayoutManager.findFirstVisibleItemPosition怎么用?Java LinearLayoutManager.findFirstVisibleItemPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.widget.LinearLayoutManager
的用法示例。
在下文中一共展示了LinearLayoutManager.findFirstVisibleItemPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onDraw
import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
final RecyclerView.LayoutManager manager = parent.getLayoutManager();
if (manager instanceof StaggeredGridLayoutManager) {
return;
}
//线性布局
final LinearLayoutManager layoutManager = (LinearLayoutManager) manager;
final int firstItem = layoutManager.findFirstVisibleItemPosition();
for (int i = 0; i < layoutManager.getChildCount(); i++) {
final int viewAdapterPosition = firstItem + i;
final View view = layoutManager.findViewByPosition(viewAdapterPosition);
if (view != null) {
mItemDecorationCallback.draw(c, mTextPaint, view,
mItemDecorationCallback.getItemOffsets(layoutManager, viewAdapterPosition),
layoutManager.getItemCount(), viewAdapterPosition);
}
}
}
示例2: onScrolled
import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
int firstVisible = layoutManager.findFirstVisibleItemPosition();
int visibleCount = Math.abs(firstVisible - layoutManager.findLastVisibleItemPosition());
int itemCount = recyclerView.getAdapter().getItemCount();
if (firstVisible != lastFirstVisible || visibleCount != lastVisibleCount
|| itemCount != lastItemCount) {
scrollListener.onScroll(null, firstVisible, visibleCount, itemCount);
lastFirstVisible = firstVisible;
lastVisibleCount = visibleCount;
lastItemCount = itemCount;
}
}
示例3: onScrolled
import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
amountAxisX += dx;
fastScrollTo(amountAxisX, mRecyclerView, loadingViewWidth, hasHeader);
fastScrollTo(amountAxisX, topRecyclerView, loadingViewWidth, hasHeader);
if (dx == 0 && dy == 0) {
return;
}
LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager();
int visibleItemCount = recyclerView.getChildCount();
int totalItemCount = manager.getItemCount();
int firstVisibleItem = manager.findFirstVisibleItemPosition();
if (totalItemCount - visibleItemCount <= firstVisibleItem && onLoadMoreListener != null && hasFooter) {
onLoadMoreListener.onLoadMore();
}
if (amountAxisX < loadingViewWidth && onLoadMoreListener != null && hasHeader) {
onLoadMoreListener.onLoadHistory();
}
if (((hasHeader && amountAxisX > loadingViewWidth) || (!hasHeader && amountAxisX > 0)) && dividerLineVisible) {
dividerLine.setVisibility(VISIBLE);
} else {
dividerLine.setVisibility(GONE);
}
}
示例4: onScrollStateChanged
import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManager instanceof LinearLayoutManager) {
LinearLayoutManager linearManager = (LinearLayoutManager) layoutManager;
int firstItemPosition = linearManager.findFirstVisibleItemPosition();
if(firstItemPosition == 0 || mContentListAdapter.getItemCount() == 0){
mRefreshLayout.setEnabled(true);
CFLog.e("V2MainFragment", "arrive top");
}
else{
mRefreshLayout.setEnabled(false);
}
}
}
示例5: renewScrollPosition
import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
/**
* This method calculates the current scroll position and its offset to help new attached
* recyclerView on window at that position and offset
*
* @see #getScrollPosition()
* @see #getScrollPositionOffset()
*/
private void renewScrollPosition(RecyclerView p_jRecyclerView) {
LinearLayoutManager layoutManager = (LinearLayoutManager) p_jRecyclerView
.getLayoutManager();
m_nScrollPosition = layoutManager.findFirstCompletelyVisibleItemPosition();
// That means there is no completely visible Position.
if (m_nScrollPosition == -1) {
m_nScrollPosition = layoutManager.findFirstVisibleItemPosition();
// That means there is just a visible item on the screen
if (layoutManager.findFirstVisibleItemPosition() == layoutManager
.findLastVisibleItemPosition()) {
// in this case we use the position which is the last & first visible item.
} else {
// That means there are 2 visible item on the screen. However, second one is not
// completely visible.
m_nScrollPosition = m_nScrollPosition + 1;
}
}
m_nScrollPositionOffset = p_jRecyclerView.getLayoutManager().findViewByPosition
(m_nScrollPosition).getLeft();
}
示例6: checkRecyclerView
import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
private static boolean checkRecyclerView(RecyclerView recyclerView) {
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManager instanceof LinearLayoutManager) {
LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
if (linearLayoutManager.getItemCount() == 0) {
return true;
}
int firstVisiblePosition = linearLayoutManager.findFirstVisibleItemPosition();
if (firstVisiblePosition == 0) {
View firstVisibleView = linearLayoutManager.findViewByPosition(firstVisiblePosition);
int top = firstVisibleView.getTop();
return top >= 0;
} else {
return false;
}
}
return false;
}
示例7: onScrolled
import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
//在这里进行第二次滚动(最后的100米!)
if (move) {
move = false;
//获取要置顶的项在当前屏幕的位置,mIndex是记录的要置顶项在RecyclerView中的位置
LinearLayoutManager mLinearLayoutManager = (LinearLayoutManager) layoutManager;
int n = mIndex - mLinearLayoutManager.findFirstVisibleItemPosition();
if (0 <= n && n < recyclerView.getChildCount()) {
//获取要置顶的项顶部离RecyclerView顶部的距离
int top = recyclerView.getChildAt(n).getTop();
//最后的移动
recyclerView.scrollBy(0, top);
}
}
}
示例8: isAtTopBeforeIceCream
import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
private static boolean isAtTopBeforeIceCream(RecyclerView recyclerView) {
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManager instanceof LinearLayoutManager) {
LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
int pos = linearLayoutManager.findFirstVisibleItemPosition();
if (linearLayoutManager.findViewByPosition(pos).getTop() == recyclerView.getPaddingTop() && pos == 0)
return true;
}
return false;
}
示例9: offset
import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
@Override
public Varargs offset(U view, Varargs varargs) {
if (varargs.narg() > 1) {
return setScrollXY(view, varargs);
} else {
LinearLayoutManager layoutManager = (LinearLayoutManager) view.getLVRecyclerView().getLayoutManager();
int position = layoutManager.findFirstVisibleItemPosition();
View firstVisiableChildView = layoutManager.findViewByPosition(position);
int itemHeight = firstVisiableChildView.getHeight();
int dy = (position) * itemHeight - firstVisiableChildView.getTop();
return varargsOf(valueOf(0), valueOf(DimenUtil.pxToDpi(dy)));
}
}
示例10: findFirstVisibleItemPosition
import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
public int findFirstVisibleItemPosition() {
int position = -1;
if (mRecyclerView.getLayoutManager() != null && excelPanelAdapter != null) {
LinearLayoutManager mLinearLayoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
int firstVisibleItem = mLinearLayoutManager.findFirstVisibleItemPosition();
if (hasHeader) {
return firstVisibleItem - 1;
}
return firstVisibleItem;
}
return position;
}
示例11: onScrolled
import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
int firstVisible = layoutManager.findFirstVisibleItemPosition();
int visibleCount = Math.abs(firstVisible - layoutManager.findLastVisibleItemPosition());
int itemCount = recyclerView.getAdapter().getItemCount();
if (firstVisible != lastFirstVisible || visibleCount != lastVisibleCount || itemCount != lastItemCount) {
scrollListener.onScroll(null, firstVisible, visibleCount, itemCount);
lastFirstVisible = firstVisible;
lastVisibleCount = visibleCount;
lastItemCount = itemCount;
}
}
示例12: chooseDropTarget
import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
private int chooseDropTarget(RecyclerView rv, int dragPosition, int curY) {
LinearLayoutManager layoutManager = ((LinearLayoutManager) rv.getLayoutManager());
int firstVisiblePosition = layoutManager.findFirstVisibleItemPosition();
if (mView.getY() < 0 && firstVisiblePosition == 0) {
return firstVisiblePosition;
}
float referenceUp = mView.getY() - mView.getTranslationY();
if ((referenceUp > curY) && mView.getTranslationY() < 0) {
if (referenceUp - curY > mView.getHeight()) {
return dragPosition - 2;
}
if (referenceUp - curY < mView.getHeight() && referenceUp - curY > 0) {
return dragPosition - 1;
}
}
float referenceDown = mView.getY() - mView.getTranslationY() + mView.getHeight();
if ((referenceDown < curY) && mView.getTranslationY() > 0) {
if (curY - referenceDown > mView.getHeight()) {
return dragPosition + 2;
}
if (curY - referenceDown < mView.getHeight() && curY - referenceDown > 0) {
return dragPosition + 1;
}
}
return -1;
}
示例13: getVisibleItemCount
import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
public int getVisibleItemCount(){
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
//only LinearLayoutManager can find last visible
if(layoutManager instanceof LinearLayoutManager){
LinearLayoutManager linearManager = (LinearLayoutManager) layoutManager;
int firstPosition = linearManager.findFirstVisibleItemPosition();
int lastPosition = linearManager.findLastVisibleItemPosition();
return lastPosition - firstPosition + 1;
}else {
throw new UnsupportedOperationException("only for Linear RecyclerView ");
}
}
示例14: getUpdatePositions
import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
private Set<Integer> getUpdatePositions() {
LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
AppsItemAdapter adapter = (AppsItemAdapter) mRecyclerView.getAdapter();
if (adapter == null || layoutManager == null) {
return Collections.emptySet();
}
int first = layoutManager.findFirstVisibleItemPosition();
int last = layoutManager.findLastVisibleItemPosition();
if (first == -1 || last == -1) {
return Collections.emptySet();
}
List<AppsInfo> appsInfoList = adapter.getAppsInfo();
BreventActivity activity = (BreventActivity) mFragment.getActivity();
if (appsInfoList.isEmpty() || activity == null) {
return Collections.emptySet();
}
Set<Integer> positions = new ArraySet<>();
final int now = BreventResponse.now();
last = Math.min(last, appsInfoList.size() - 1);
for (int i = first; i <= last; ++i) {
AppsInfo info = appsInfoList.get(i);
if (info.isPackage()) {
positions.add(i);
int inactive = activity.getInactive(info.packageName);
AppsItemViewHolder viewHolder = getViewHolder(i);
if (viewHolder != null) {
viewHolder.inactive = inactive;
if (inactive > 0) {
long diff = now - inactive;
viewHolder.inactiveView.setText(DateUtils.formatElapsedTime(diff));
} else {
viewHolder.inactiveView.setText(null);
}
}
}
}
return positions;
}
示例15: needToRequestNextPage
import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
private boolean needToRequestNextPage() {
LinearLayoutManager layoutManager = (LinearLayoutManager) getLayoutManager();
int visibleItemCount = layoutManager.getChildCount();
int totalItemCount = getAdapter().getItemCount();
int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
return firstVisibleItemPosition > 0 && firstVisibleItemPosition + visibleItemCount > totalItemCount - 5;
}