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


Java LinearLayoutManager.findViewByPosition方法代码示例

本文整理汇总了Java中android.support.v7.widget.LinearLayoutManager.findViewByPosition方法的典型用法代码示例。如果您正苦于以下问题:Java LinearLayoutManager.findViewByPosition方法的具体用法?Java LinearLayoutManager.findViewByPosition怎么用?Java LinearLayoutManager.findViewByPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v7.widget.LinearLayoutManager的用法示例。


在下文中一共展示了LinearLayoutManager.findViewByPosition方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: calculateSnapDistance

import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
/**
 * Calculates the distance between the RecyclerView's anchor, either the start, center or end,
 * and the View which is closest to the anchor.
 *
 * @return The distance between RecyclerView anchor and View closest to anchor
 */
private int calculateSnapDistance() {
    LinearLayoutManager linearLayoutManager = (LinearLayoutManager) getLayoutManager();

    int parentAnchor = getParentAnchor(orientation, anchor);

    int lastVisibleItemPosition = linearLayoutManager.findLastVisibleItemPosition();
    int firstVisibleItemPosition = linearLayoutManager.findFirstVisibleItemPosition();

    View currentViewClosestToAnchor = linearLayoutManager.findViewByPosition(firstVisibleItemPosition);

    int currentViewClosestToAnchorDistance = parentAnchor - getViewAnchor(currentViewClosestToAnchor, orientation, anchor);

    for(int i = firstVisibleItemPosition + 1; i <= lastVisibleItemPosition; i++) {
        View view = linearLayoutManager.findViewByPosition(i);
        int distanceToAnchor = parentAnchor - getViewAnchor(view, orientation, anchor);

        if (Math.abs(distanceToAnchor) < Math.abs(currentViewClosestToAnchorDistance)) {
            currentViewClosestToAnchorDistance = distanceToAnchor;
        }
    }

    return currentViewClosestToAnchorDistance;
}
 
开发者ID:Dan-TD,项目名称:SnappyRecyclerView,代码行数:30,代码来源:SnappingRecyclerView.java

示例3: 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

示例4: 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

示例5: findRealFirstVisibleItemPosition

import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
public int findRealFirstVisibleItemPosition(int pos) {
    View view;
    final LinearLayoutManager linearLayoutManager =
            (LinearLayoutManager) mRecyclerView.getLayoutManager();

    while (pos > 0) {
        view = linearLayoutManager.findViewByPosition(pos - 1);
        if (view == null) {
            break;
        }
        pos = pos - 1;
    }
    return pos;
}
 
开发者ID:reyanshmishra,项目名称:Rey-MusicPlayer,代码行数:15,代码来源:TracksSubFragment.java

示例6: scrollRvDate

import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
public void scrollRvDate(int position){
    if (position > 1) {
        LinearLayoutManager layoutManager = (LinearLayoutManager) rv_date.getLayoutManager();
        View view = layoutManager.findViewByPosition(position);
        int itemWidth = view.getWidth();
        int left = view.getLeft();

        rv_date.smoothScrollBy(left - (int) (itemWidth * 1.5) + PixelUtil.dp2px(context, 30), 0);
    }
}
 
开发者ID:mangestudio,项目名称:GCSApp,代码行数:11,代码来源:MoneyHistoryDelegate.java

示例7: onDraw

import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    super.onDraw(c, parent, state);

    final RecyclerView.LayoutManager manager = parent.getLayoutManager();

    int itemCount = manager.getItemCount();
    if (itemCount < 1) {
        //如果只有1个item, 直接返回;
        return;
    }
    if (manager instanceof GridLayoutManager) {
        //网格布局
        drawGrid(c, manager);
    } else if (manager instanceof StaggeredGridLayoutManager) {
        //暂不支持...
    } else {
        //线性布局
        final LinearLayoutManager layoutManager = (LinearLayoutManager) manager;
        final int firstItem = layoutManager.findFirstVisibleItemPosition();
        for (int i = 0; i < layoutManager.getChildCount(); i++) {
            int adapterPosition = firstItem + i;

            final View view = layoutManager.findViewByPosition(adapterPosition);

            if (itemCount == 1 || adapterPosition == itemCount - 1) {
                //第一个, 或者最后一个
                if (!drawLastHLine && !drawLastVLine) {
                    continue;
                }
            }

            if (view != null) {
                if (layoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) {
                    //水平
                    drawDrawableV(c, view);
                } else {
                    //垂直
                    drawDrawableH(c, view);
                }
            }
        }
    }
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:45,代码来源:RBaseItemDecoration.java

示例8: calculateSnapViewPosition

import android.support.v7.widget.LinearLayoutManager; //导入方法依赖的package包/类
/**
 * Finds the position of the View which is closest to the RecyclerView's anchor, either the
 * RecyclerView's start, center or end
 *
 * @return The position of the View closest the to RecyclerView's anchor
 */
private int calculateSnapViewPosition() {
    LinearLayoutManager linearLayoutManager = (LinearLayoutManager) getLayoutManager();

    int parentAnchor = getParentAnchor(orientation, anchor);

    int lastVisibleItemPosition = linearLayoutManager.findLastVisibleItemPosition();
    int firstVisibleItemPosition = linearLayoutManager.findFirstVisibleItemPosition();

    View currentViewClosestToAnchor = linearLayoutManager.findViewByPosition(firstVisibleItemPosition);

    int currentViewClosestToAnchorDistance = parentAnchor - getViewAnchor(currentViewClosestToAnchor, orientation, anchor);

    int currentViewClosestToAnchorPosition = firstVisibleItemPosition;

    for(int i = firstVisibleItemPosition + 1; i <= lastVisibleItemPosition; i++) {
        View view = linearLayoutManager.findViewByPosition(i);

        int distanceToCenter = parentAnchor - getViewAnchor(view, orientation, anchor);

        if (Math.abs(distanceToCenter) < Math.abs(currentViewClosestToAnchorDistance)) {
            currentViewClosestToAnchorPosition = i;
            currentViewClosestToAnchorDistance = distanceToCenter;
        }
    }

    return currentViewClosestToAnchorPosition;
}
 
开发者ID:Dan-TD,项目名称:SnappyRecyclerView,代码行数:34,代码来源:SnappingRecyclerView.java


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