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


Java RecyclerView.getLayoutManager方法代碼示例

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


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

示例1: isTop

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
 * is position align top of recycler view
 * 從當前位置找起,隻要找到一個跟自己的spanIndex一樣的就說明不是第一行,或者已經查找過的spancount >= spanCount說明不是第一行
 *
 * @param parent
 * @param position
 * @param totalSpanCount
 * @return
 */
private boolean isTop(RecyclerView parent, int position, int totalSpanCount) {
    if (parent.getLayoutManager() instanceof GridLayoutManager) {
        GridLayoutManager.SpanSizeLookup sizeLookup = ((GridLayoutManager) parent.getLayoutManager()).getSpanSizeLookup();
        if (sizeLookup != null) {
            int currentSpanIndex = sizeLookup.getSpanIndex(position, totalSpanCount);
            int lookupedSpanCount = 0;
            for (int i = position - 1; i >= 0; i--) {
                lookupedSpanCount = lookupedSpanCount + sizeLookup.getSpanSize(i);
                if (lookupedSpanCount >= totalSpanCount) {
                    return false;
                }
                if (sizeLookup.getSpanIndex(i, totalSpanCount) == currentSpanIndex) {
                    return false;
                }
            }
            return true;
        }
    } else if (parent.getLayoutManager() instanceof StaggeredGridLayoutManager) {
        return position < totalSpanCount;//staggered 的每一列一個span
    }
    return false;
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:32,代碼來源:DividerGridItemDecoration.java

示例2: onAttachedToRecyclerView

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
    mInnerAdapter.onAttachedToRecyclerView(recyclerView);

    LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
        final GridLayoutManager.SpanSizeLookup spanSizeLookup = gridLayoutManager.getSpanSizeLookup();

        gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                int viewType = getItemViewType(position);
                if (viewType == TYPE_REFRESH_HEADER) {
                    return gridLayoutManager.getSpanCount();
                } else if (viewType == TYPE_LOADMORE_FOOTER) {
                    return gridLayoutManager.getSpanCount();
                }
                if (spanSizeLookup != null)
                    return spanSizeLookup.getSpanSize(position);
                return 1;
            }
        });
        gridLayoutManager.setSpanCount(gridLayoutManager.getSpanCount());
    }
}
 
開發者ID:BittleDragon,項目名稱:RefreshLoadRecyclerview,代碼行數:27,代碼來源:ExcellentRecyclerview.java

示例3: onAttachedToRecyclerView

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onAttachedToRecyclerView(final RecyclerView recyclerView) {
    super.onAttachedToRecyclerView(recyclerView);
    RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
    if (manager instanceof GridLayoutManager) {
        final GridLayoutManager gridManager = ((GridLayoutManager) manager);
        gridManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                int type = getItemViewType(position);
                if (mSpanSizeLookup == null) {
                    return (type == EMPTY_VIEW || type == LOADING_VIEW || type == FETCHING_VIEW) ? gridManager.getSpanCount() : 1;
                } else {
                    return (type == EMPTY_VIEW || type == LOADING_VIEW || type == FETCHING_VIEW) ? gridManager
                            .getSpanCount() : mSpanSizeLookup.getSpanSize(gridManager, position - getFetchMoreViewCount());
                }
            }
        });
    }
}
 
開發者ID:newDeepLearing,項目名稱:decoy,代碼行數:21,代碼來源:BaseFetchLoadAdapter.java

示例4: onScrolled

import android.support.v7.widget.RecyclerView; //導入方法依賴的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

示例5: isLastRaw

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private boolean isLastRaw(RecyclerView parent, int pos, int spanCount,
                          int childCount) {
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        childCount = childCount - childCount % spanCount;
        if (pos >= childCount)// 如果是最後一行,則不需要繪製底部
            return true;
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        int orientation = ((StaggeredGridLayoutManager) layoutManager)
                .getOrientation();
        // StaggeredGridLayoutManager 且縱向滾動
        if (orientation == StaggeredGridLayoutManager.VERTICAL) {
            childCount = childCount - childCount % spanCount;
            // 如果是最後一行,則不需要繪製底部
            if (pos >= childCount)
                return true;
            // StaggeredGridLayoutManager 且橫向滾動
        } else {
            // 如果是最後一行,則不需要繪製底部
            if ((pos + 1) % spanCount == 0) {
                return true;
            }
        }
    }
    return false;
}
 
開發者ID:zuoni1018,項目名稱:CoordinatorLayoutExample-master,代碼行數:27,代碼來源:DividerGridItemDecoration.java

示例6: RecordPatientRemarkListCustomAdapter

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
public RecordPatientRemarkListCustomAdapter(Context context, ArrayList<Symptom> list, ArrayList<PatientRemark> remarks, RecyclerView recyclerView, OnAdapterSupport listener, AddRemarkFromListActivity activity) {
    this.context = context;
    this.remarks = remarks;
    this.list = list;
    this.onAdapterSupport = listener;
    this.activity = (AddRemarkFromListActivity) activity;

    if (recyclerView.getLayoutManager() instanceof LinearLayoutManager) {
        recyclerView.addOnScrollListener(new ScrollListener() {
            @Override
            public void onHide() {
                hideViews();
            }

            @Override
            public void onShow() {
                showViews();
            }
        });
    }
}
 
開發者ID:pooi,項目名稱:Nearby,代碼行數:22,代碼來源:RecordPatientRemarkListCustomAdapter.java

示例7: onAttachedToRecyclerView

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onAttachedToRecyclerView(final RecyclerView recyclerView) {
    super.onAttachedToRecyclerView(recyclerView);
    RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
    if (manager instanceof GridLayoutManager) {
        final GridLayoutManager gridManager = ((GridLayoutManager) manager);
        gridManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                int type = getItemViewType(position);
                if (mSpanSizeLookup == null)
                    return (type == EMPTY_VIEW || type == HEADER_VIEW || type == FOOTER_VIEW || type == LOADING_VIEW) ? gridManager.getSpanCount() : 1;
                else
                    return (type == EMPTY_VIEW || type == HEADER_VIEW || type == FOOTER_VIEW || type == LOADING_VIEW) ? gridManager.getSpanCount() : mSpanSizeLookup.getSpanSize(gridManager, position - getHeaderLayoutCount());
            }
        });
    }
    recyclerView.post(new Runnable() {
        @Override
        public void run() {
            if (mRequestLoadMoreListener != null && pageSize == -1) {
                RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
                int visibleItemCount = layoutManager.getChildCount();
                Log.e("visibleItemCount", visibleItemCount + "");
                openLoadMore(visibleItemCount);
            }
        }
    });

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

示例8: isLastRow

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
public boolean isLastRow(int itemPosition, RecyclerView parent) {
    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        int spanCount = ((GridLayoutManager) layoutManager).getSpanCount();
        int itemCount = parent.getAdapter().getItemCount();
        if ((itemCount - itemPosition - 1) < spanCount)
            return true;
    }
    return false;
}
 
開發者ID:GitLqr,項目名稱:MaterialDesignDemo,代碼行數:11,代碼來源:MyDecorationTwo.java

示例9: isLastRaw

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private boolean isLastRaw(RecyclerView parent, int pos, int spanCount,
                          int childCount) {
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        childCount = childCount - childCount % spanCount;
        if (pos >= childCount)// 如果是最後一行,則不需要繪製底部
            return true;
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        int orientation = ((StaggeredGridLayoutManager) layoutManager)
                .getOrientation();
        // StaggeredGridLayoutManager 且縱向滾動
        if (orientation == StaggeredGridLayoutManager.VERTICAL) {
            childCount = childCount - childCount % spanCount;
            // 如果是最後一行,則不需要繪製底部
            if (pos >= childCount)
                return true;
        } else
        // StaggeredGridLayoutManager 且橫向滾動
        {
            // 如果是最後一行,則不需要繪製底部
            if ((pos + 1) % spanCount == 0) {
                return true;
            }
        }
    }
    return false;
}
 
開發者ID:yiwent,項目名稱:Mobike,代碼行數:28,代碼來源:DividerGridItemDecoration.java

示例10: onAttachedToRecyclerView

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
    super.onAttachedToRecyclerView(recyclerView);
    RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
    if (manager instanceof GridLayoutManager) {
        final GridLayoutManager gridManager = ((GridLayoutManager) manager);
        gridManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                return (isHeader(position) || isFooter(position))
                        ? gridManager.getSpanCount() : 1;
            }
        });
    }
}
 
開發者ID:joelan,項目名稱:ClouldReader,代碼行數:16,代碼來源:WrapAdapter.java

示例11: onScrolled

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

    final LinearLayoutManager linearLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();

    totalItemCount = linearLayoutManager.getItemCount();
    lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
    if (!loading && totalItemCount <= (lastVisibleItem + visibleThreshold)) {
        // End has been reached
        // Do something
        loading = true;
        if (onLoadMoreListener != null) {
            onLoadMoreListener.onLoadMore();
        }
    }
    // 여기까지 무한 스크롤

    if (scrolledDistance > HIDE_THRESHOLD && controlsVisible) {
        onHide();
        controlsVisible = false;
        scrolledDistance = 0;
    } else if (scrolledDistance < -HIDE_THRESHOLD && !controlsVisible) {
        onShow();
        controlsVisible = true;
        scrolledDistance = 0;
    }

    if((controlsVisible && dy>0) || (!controlsVisible && dy<0)) {
        scrolledDistance += dy;
    }
    // 여기까지 툴바 숨기기
}
 
開發者ID:pooi,項目名稱:Nearby,代碼行數:34,代碼來源:PatientSymptomListCustomAdapter.java

示例12: attach

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
 * Should be called after recyclerView setup with its layoutManager and adapter
 *
 * @param recyclerView the RecyclerView
 */
public void attach(RecyclerView recyclerView) {
    final LinearLayoutManager layoutManager
        = (LinearLayoutManager) recyclerView.getLayoutManager();
    recyclerView.addOnScrollListener(
        new EndlessScrollListener(layoutManager, loadMoreSubject));
}
 
開發者ID:drakeet,項目名稱:rebase-android,代碼行數:12,代碼來源:LoadMoreDelegate.java

示例13: compatibleWithLayoutManager

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
 * compatible with recyclerview layoutmanager
 *
 * @param parent
 */
private void compatibleWithLayoutManager(RecyclerView parent) {

    if (parent.getLayoutManager() != null) {
        if (parent.getLayoutManager() instanceof GridLayoutManager) {
            mMode = MODE_GRID;
        } else if (parent.getLayoutManager() instanceof LinearLayoutManager) {
            if (((LinearLayoutManager) parent.getLayoutManager()).getOrientation() == LinearLayout.HORIZONTAL) {
                mMode = MODE_VERTICAL;
            } else {
                mMode = MODE_HORIZONTAL;
            }
        }
    }
}
 
開發者ID:z-chu,項目名稱:FriendBook,代碼行數:20,代碼來源:RecyclerViewItemDecoration.java

示例14: fastScrollTo

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private void fastScrollTo(int amountAxis, RecyclerView recyclerView, int offset, boolean hasHeader) {
    int position = 0, width = normalCellWidth;
    if (amountAxis >= offset && hasHeader) {
        amountAxis -= offset;
        position++;
    }
    position += amountAxis / width;
    amountAxis %= width;
    LinearLayoutManager linearLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
    //call this method the OnScrollListener's onScrolled will be called,but dx and dy always be zero.
    linearLayoutManager.scrollToPositionWithOffset(position, -amountAxis);
}
 
開發者ID:zhouchaoyuan,項目名稱:excelPanel,代碼行數:13,代碼來源:ExcelPanel.java

示例15: getSpanCount

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private int getSpanCount(RecyclerView parent) {
    // 列數
    int spanCount = -1;
    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {

        spanCount = ((GridLayoutManager) layoutManager).getSpanCount();
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        spanCount = ((StaggeredGridLayoutManager) layoutManager)
                .getSpanCount();
    }
    return spanCount;
}
 
開發者ID:ynztlxdeai,項目名稱:TextReader,代碼行數:14,代碼來源:SupportGridItemDecoration.java


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