本文整理匯總了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;
}
示例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());
}
}
示例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());
}
}
});
}
}
示例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;
}
}
示例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;
}
示例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();
}
});
}
}
示例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);
}
}
});
}
示例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;
}
示例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;
}
示例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;
}
});
}
}
示例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;
}
// 여기까지 툴바 숨기기
}
示例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));
}
示例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;
}
}
}
}
示例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);
}
示例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;
}