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


Java GridLayoutManager.findFirstCompletelyVisibleItemPosition方法代碼示例

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


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

示例1: doClickOtherToNavigation

import android.support.v7.widget.GridLayoutManager; //導入方法依賴的package包/類
private void doClickOtherToNavigation(ViewGroup parent, int position, MyViewHolder myHolder) {
    RecyclerView recyclerView = (RecyclerView) parent;
    LayoutManager manager = recyclerView.getLayoutManager();
    View currentView = manager.findViewByPosition(myHolder.getAdapterPosition());
    View preTargetView = manager.findViewByPosition(this.mTopSize);
    GridLayoutManager gridLayoutManager = (GridLayoutManager) manager;
    int spanCount = gridLayoutManager.getSpanCount();
    int targetPosition = this.mTopSize + 1;
    if (recyclerView.indexOfChild(preTargetView) >= 0) {
        int targetX = preTargetView.getLeft();
        int targetY = preTargetView.getTop();
        if ((targetPosition - 1) % spanCount == 0) {
            View targetView = manager.findViewByPosition(targetPosition);
            targetX = targetView.getLeft();
            targetY = targetView.getTop();
        } else {
            targetX += preTargetView.getWidth() + UIsUtils.dipToPx(TitleBar.SHAREBTN_RIGHT_MARGIN);
            if (gridLayoutManager.findLastVisibleItemPosition() == getItemCount() - 1 && (((getItemCount() - 1) - this.mTopSize) - 2) % spanCount == 0) {
                if (gridLayoutManager.findFirstVisibleItemPosition() != 0) {
                    targetY += preTargetView.getHeight() + UIsUtils.dipToPx(TitleBar.SHAREBTN_RIGHT_MARGIN);
                } else if (gridLayoutManager.findFirstCompletelyVisibleItemPosition() != 0) {
                    targetY += (-recyclerView.getChildAt(0).getTop()) - recyclerView.getPaddingTop();
                }
            }
        }
        moveOtherToMy(myHolder);
        startAnimation(recyclerView, currentView, (float) targetX, (float) targetY);
        return;
    }
    moveOtherToMy(myHolder);
    int index = (this.mTopSize % spanCount) - 1;
    if (index < 0) {
        index = spanCount - 1;
    }
    startAnimation(recyclerView, currentView, (float) ((currentView.getWidth() * index) + (index == 0 ? 0 : (index - 1) * UIsUtils.dipToPx(TitleBar.SHAREBTN_RIGHT_MARGIN))), 0.0f);
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:37,代碼來源:ChannelFragmentAdapter.java

示例2: onScrolled

import android.support.v7.widget.GridLayoutManager; //導入方法依賴的package包/類
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    int lastItem = 0;
    int firstItem = 0;
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    int totalItemCount = layoutManager.getItemCount();
    if (layoutManager instanceof GridLayoutManager) {
        GridLayoutManager gridLayoutManager = ((GridLayoutManager) layoutManager);
        firstItem = gridLayoutManager.findFirstCompletelyVisibleItemPosition();
        //Position to find the final item of the current LayoutManager
        lastItem = gridLayoutManager.findLastCompletelyVisibleItemPosition();
        if (lastItem == -1) lastItem = gridLayoutManager.findLastVisibleItemPosition();
    } else if (layoutManager instanceof LinearLayoutManager) {
        LinearLayoutManager linearLayoutManager = ((LinearLayoutManager) layoutManager);
        firstItem = linearLayoutManager.findFirstCompletelyVisibleItemPosition();
        lastItem = linearLayoutManager.findLastCompletelyVisibleItemPosition();
        if (lastItem == -1) lastItem = linearLayoutManager.findLastVisibleItemPosition();
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        StaggeredGridLayoutManager staggeredGridLayoutManager = ((StaggeredGridLayoutManager) layoutManager);
        // since may lead to the final item has more than one StaggeredGridLayoutManager the particularity of the so here that is an array
        // this array into an array of position and then take the maximum value that is the last show the position value
        int[] lastPositions = new int[((StaggeredGridLayoutManager) layoutManager).getSpanCount()];
        staggeredGridLayoutManager.findLastCompletelyVisibleItemPositions(lastPositions);
        lastItem = findMax(lastPositions);
        firstItem = staggeredGridLayoutManager.findFirstVisibleItemPositions(lastPositions)[0];
    }
    if (firstItem == 0 || firstItem == RecyclerView.NO_POSITION) {
        if (mPullLoadMoreRecyclerView.getPullRefreshEnable())
            mPullLoadMoreRecyclerView.setSwipeRefreshEnable(true);
    } else {
        mPullLoadMoreRecyclerView.setSwipeRefreshEnable(false);
    }
    if (mPullLoadMoreRecyclerView.getPushRefreshEnable()
            && !mPullLoadMoreRecyclerView.isRefresh()
            && mPullLoadMoreRecyclerView.isHasMore()
            && (lastItem == totalItemCount - 1)
            && !mPullLoadMoreRecyclerView.isLoadMore()
            && (dx > 0 || dy > 0)) {
        mPullLoadMoreRecyclerView.setIsLoadMore(true);
        mPullLoadMoreRecyclerView.loadMore();
    }

}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:45,代碼來源:RecyclerViewOnScroll.java


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