当前位置: 首页>>代码示例>>Java>>正文


Java LinearLayoutManager.findFirstVisibleItemPosition方法代码示例

本文整理汇总了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);
        }
    }
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:21,代码来源:RExItemDecoration.java

示例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;
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:RecyclerToListViewScrollListener.java

示例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);
    }
}
 
开发者ID:zhouchaoyuan,项目名称:excelPanel,代码行数:26,代码来源:ExcelPanel.java

示例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);
        }
    }
}
 
开发者ID:stdnull,项目名称:RunMap,代码行数:17,代码来源:V2MainFragment.java

示例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();
}
 
开发者ID:evrencoskun,项目名称:TableView,代码行数:31,代码来源:HorizontalRecyclerViewListener.java

示例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;
}
 
开发者ID:liyuanhust,项目名称:LoadMoreHelper,代码行数:19,代码来源:PtrFramePullView.java

示例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);
        }
    }
}
 
开发者ID:ebridfighter,项目名称:GongXianSheng,代码行数:18,代码来源:RefreshRecyclerView.java

示例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;
}
 
开发者ID:FreeSunny,项目名称:Amazing,代码行数:11,代码来源:SuperSwipeHelper.java

示例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)));
    }
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:14,代码来源:UIRecyclerViewMethodMapper.java

示例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;
}
 
开发者ID:zhouchaoyuan,项目名称:excelPanel,代码行数:13,代码来源:ExcelPanel.java

示例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;
    }
}
 
开发者ID:hushengjun,项目名称:FastAndroid,代码行数:16,代码来源:RecyclerToListViewScrollListener.java

示例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;
}
 
开发者ID:qinhehu,项目名称:Gesture,代码行数:30,代码来源:ItemTouchListener.java

示例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 ");
    }
}
 
开发者ID:ThirtyDegreesRay,项目名称:OpenHub,代码行数:13,代码来源:ListFragment.java

示例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;
}
 
开发者ID:brevent,项目名称:Brevent,代码行数:39,代码来源:AppsItemHandler.java

示例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;
}
 
开发者ID:jainsahab,项目名称:AndroidSnooper,代码行数:8,代码来源:PaginatedRecyclerView.java


注:本文中的android.support.v7.widget.LinearLayoutManager.findFirstVisibleItemPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。