當前位置: 首頁>>代碼示例>>Java>>正文


Java StaggeredGridLayoutManager.findFirstCompletelyVisibleItemPositions方法代碼示例

本文整理匯總了Java中android.support.v7.widget.StaggeredGridLayoutManager.findFirstCompletelyVisibleItemPositions方法的典型用法代碼示例。如果您正苦於以下問題:Java StaggeredGridLayoutManager.findFirstCompletelyVisibleItemPositions方法的具體用法?Java StaggeredGridLayoutManager.findFirstCompletelyVisibleItemPositions怎麽用?Java StaggeredGridLayoutManager.findFirstCompletelyVisibleItemPositions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.v7.widget.StaggeredGridLayoutManager的用法示例。


在下文中一共展示了StaggeredGridLayoutManager.findFirstCompletelyVisibleItemPositions方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: canChildScrollUp

import android.support.v7.widget.StaggeredGridLayoutManager; //導入方法依賴的package包/類
public static boolean canChildScrollUp(View view) {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (view instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) view;
            return absListView.getChildCount() > 0
                    && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0)
                    .getTop() < absListView.getPaddingTop());
        } else if(view instanceof  RecyclerView){
            RecyclerView recyclerView = (RecyclerView)view;
            RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
            if(layoutManager instanceof LinearLayoutManager){
                int position = ((LinearLayoutManager) layoutManager).findFirstCompletelyVisibleItemPosition();
                return position != 0;
            }else{
                if(layoutManager instanceof StaggeredGridLayoutManager ){
                    StaggeredGridLayoutManager stagger = (StaggeredGridLayoutManager) layoutManager;
                    int[] positions = stagger.findFirstCompletelyVisibleItemPositions(null);
                    return positions[0] != 0;
                }else{
                    throw new RuntimeException("can not support this LayoutManager ");
                }
            }
        }else{
            return view.getScrollY() > 0;
        }
    } else {
        return view.canScrollVertically(-1);
    }
}
 
開發者ID:liu-xiao-dong,項目名稱:JD-Test,代碼行數:30,代碼來源:PtrDefaultHandler.java

示例2: findFirstCompletelyVisibleItemPosition

import android.support.v7.widget.StaggeredGridLayoutManager; //導入方法依賴的package包/類
public static int findFirstCompletelyVisibleItemPosition(RecyclerView recyclerView) {
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    int firstPosition;
    if (layoutManager instanceof LinearLayoutManager) {
        firstPosition = ((LinearLayoutManager) layoutManager).findFirstCompletelyVisibleItemPosition();
    } else if (layoutManager instanceof GridLayoutManager) {
        firstPosition = ((LinearLayoutManager) layoutManager).findFirstCompletelyVisibleItemPosition();
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
        int[] lastPositions = new int[staggeredGridLayoutManager.getSpanCount()];
        staggeredGridLayoutManager.findFirstCompletelyVisibleItemPositions(lastPositions);
        firstPosition = findMin(lastPositions);
    } else {
        throw new RuntimeException(
                "Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
    }
    return firstPosition;
}
 
開發者ID:LonelyMushroom,項目名稱:aarLibrary,代碼行數:19,代碼來源:Utils.java

示例3: getFirstVisiblePosition

import android.support.v7.widget.StaggeredGridLayoutManager; //導入方法依賴的package包/類
private int getFirstVisiblePosition() {
    int position;
    if (getLayoutManager() instanceof LinearLayoutManager) {
        position = ((LinearLayoutManager) getLayoutManager()).findFirstCompletelyVisibleItemPosition();
    } else if (getLayoutManager() instanceof GridLayoutManager) {
        position = ((GridLayoutManager) getLayoutManager()).findFirstCompletelyVisibleItemPosition();
    } else {
        StaggeredGridLayoutManager layoutManager = (StaggeredGridLayoutManager) getLayoutManager();
        int[] firstPositions =
                layoutManager.findFirstCompletelyVisibleItemPositions(new int[layoutManager.getSpanCount()]);
        position = getMinPosition(firstPositions);
    }
    return position;
}
 
開發者ID:littleloulou,項目名稱:PullToRefreshRecyclerView,代碼行數:15,代碼來源:PullToRefreshRecyclerView.java

示例4: calculateFirstVisibleItemPos

import android.support.v7.widget.StaggeredGridLayoutManager; //導入方法依賴的package包/類
/**
 * 計算第一個元素的位置
 */

private int calculateFirstVisibleItemPos(int type, RecyclerView.LayoutManager layoutManager, int firstVisibleItemPosition) {
    switch (type) {
        case TYPE_LINEAR:
            mLastVisibleItemPosition = ((LinearLayoutManager) layoutManager)
                    .findLastVisibleItemPosition();
            firstVisibleItemPosition = ((LinearLayoutManager) layoutManager)
                    .findFirstVisibleItemPosition();
            break;
        case TYPE_GRID:
            mLastVisibleItemPosition = ((GridLayoutManager) layoutManager)
                    .findLastVisibleItemPosition();
            firstVisibleItemPosition = ((GridLayoutManager) layoutManager)
                    .findFirstVisibleItemPosition();
            break;
        case TYPE_STAGGERED_GRID:
            StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
            if (mLastPositions == null) {
                mLastPositions = new int[staggeredGridLayoutManager.getSpanCount()];
            }
            mLastPositions = staggeredGridLayoutManager
                    .findLastVisibleItemPositions(mLastPositions);
            mLastVisibleItemPosition = findMax(mLastPositions);
            staggeredGridLayoutManager.findFirstCompletelyVisibleItemPositions(mLastPositions);
            firstVisibleItemPosition = findMax(mLastPositions);
            break;
        default:
            break;
    }
    return firstVisibleItemPosition;
}
 
開發者ID:imliujun,項目名稱:LJFramework,代碼行數:35,代碼來源:OnRcvScrollListener.java

示例5: onScrolled

import android.support.v7.widget.StaggeredGridLayoutManager; //導入方法依賴的package包/類
@Override
public void onScrolled(int dx, int dy) {
    super.onScrolled(dx, dy);

    int firstVisibleItemPosition = 0;
    LayoutManager layoutManager = getLayoutManager();

    if (layoutManagerType == null) {
        if (layoutManager instanceof LinearLayoutManager) {
            layoutManagerType = SRecyclerView.LayoutManagerType.LinearLayout;
        } else if (layoutManager instanceof GridLayoutManager) {
            layoutManagerType = SRecyclerView.LayoutManagerType.GridLayout;
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            layoutManagerType = SRecyclerView.LayoutManagerType.StaggeredGridLayout;
        } else {
            throw new RuntimeException(
                    "Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
        }
    }

    switch (layoutManagerType) {
        case LinearLayout:
            firstVisibleItemPosition = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
            lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
            break;
        case GridLayout:
            firstVisibleItemPosition = ((GridLayoutManager) layoutManager).findFirstVisibleItemPosition();
            lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
            break;
        case StaggeredGridLayout:
            StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
            if (lastPositions == null) {
                lastPositions = new int[staggeredGridLayoutManager.getSpanCount()];
            }
            staggeredGridLayoutManager.findLastVisibleItemPositions(lastPositions);
            lastVisibleItemPosition = findMax(lastPositions);
            staggeredGridLayoutManager.findFirstCompletelyVisibleItemPositions(lastPositions);
            firstVisibleItemPosition = findMax(lastPositions);
            break;
    }

    // 根據類型來計算出第一個可見的item的位置,由此判斷是否觸發到底部的監聽器
    // 計算並判斷當前是向上滑動還是向下滑動
    calculateScrollUpOrDown(firstVisibleItemPosition, dy);
    // 移動距離超過一定的範圍,我們監聽就沒有啥實際的意義了
    mScrolledXDistance += dx;
    mScrolledYDistance += dy;
    mScrolledXDistance = (mScrolledXDistance < 0) ? 0 : mScrolledXDistance;
    mScrolledYDistance = (mScrolledYDistance < 0) ? 0 : mScrolledYDistance;
    if (mIsScrollDown && (dy == 0)) {
        mScrolledYDistance = 0;
    }
    //Be careful in here
    if (null != mLScrollListener) {
        mLScrollListener.onScrolled(mScrolledXDistance, mScrolledYDistance);
    }

}
 
開發者ID:magicbaby810,項目名稱:SRecyclerView,代碼行數:59,代碼來源:SRecyclerView.java

示例6: onScrolled

import android.support.v7.widget.StaggeredGridLayoutManager; //導入方法依賴的package包/類
@Override
public void onScrolled(int dx, int dy) {
    super.onScrolled(dx, dy);
    int firstVisibleItemPosition = 0;
    LayoutManager layoutManager = getLayoutManager();
    if (mLayoutManagerType == null) {
        if (layoutManager instanceof LinearLayoutManager) {
            mLayoutManagerType = LayoutManagerType.LINEAR_LAYOUT;
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            mLayoutManagerType = LayoutManagerType.STAGGERED_GRID_LAYOUT;
        } else if (layoutManager instanceof GridLayoutManager) {
            mLayoutManagerType = LayoutManagerType.GRID_LAYOUT;
        } else {
            throw new RuntimeException("老鐵,你沒設置布局管理器,還是設置了什麽奇怪的類型");
        }
    }

    switch (mLayoutManagerType) {
        case LINEAR_LAYOUT:
            firstVisibleItemPosition = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
            mLastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastCompletelyVisibleItemPosition();
            break;
        case STAGGERED_GRID_LAYOUT:
            firstVisibleItemPosition = ((GridLayoutManager) layoutManager).findFirstVisibleItemPosition();
            mLastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
            break;
        case GRID_LAYOUT:
            StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
            if (mLastVisibleItemPositions == null) {
                mLastVisibleItemPositions = new int[staggeredGridLayoutManager.getSpanCount()];
            }
            staggeredGridLayoutManager.findLastVisibleItemPositions(mLastVisibleItemPositions);
            mLastVisibleItemPosition = findMax(mLastVisibleItemPositions);
            staggeredGridLayoutManager.findFirstCompletelyVisibleItemPositions(mLastVisibleItemPositions);
            firstVisibleItemPosition = findMax(mLastVisibleItemPositions);
            break;
        default:
            break;
    }

    calculateScrollUpOrDown(firstVisibleItemPosition, dy);
    mScrolledXDistance += dx;
    mScrolledYDistance += dy;
    mScrolledXDistance = (mScrolledXDistance < 0) ? 0 : mScrolledXDistance;
    mScrolledYDistance = (mScrolledYDistance < 0) ? 0 : mScrolledYDistance;
    if (mIsUpToDown && (dy == 0)) {
        mScrolledYDistance = 0;
    }

    if (mUltimateScrollLister != null) {
        mUltimateScrollLister.onScrolled(mScrolledXDistance, mScrolledYDistance);
    }
}
 
開發者ID:yedashen,項目名稱:UltimateRecyclerView,代碼行數:54,代碼來源:UltimateRecyclerView.java


注:本文中的android.support.v7.widget.StaggeredGridLayoutManager.findFirstCompletelyVisibleItemPositions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。