當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。