本文整理匯總了Java中android.support.v7.widget.RecyclerView.State方法的典型用法代碼示例。如果您正苦於以下問題:Java RecyclerView.State方法的具體用法?Java RecyclerView.State怎麽用?Java RecyclerView.State使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v7.widget.RecyclerView
的用法示例。
在下文中一共展示了RecyclerView.State方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onDraw
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
boolean isReverseLayout = getIsReverseLayout(parent);
int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = parent.getChildAt(i);
int adapterPosition = parent.getChildAdapterPosition(child);
if (adapterPosition < 0) {
return;
}
ItemBinder binder = adapter.getBinderForPosition(adapterPosition);
if (binder.isItemDecorationEnabled()) {
int itemPosition = adapter.getItemPositionInManager(parent.getChildAdapterPosition(child));
int positionType = getPositionType(parent, adapterPosition, itemPosition, isReverseLayout);
binder.onDraw(canvas, parent, child, itemPosition, positionType);
}
}
}
示例2: computeScrollRange
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private int computeScrollRange(RecyclerView.State state) {
if (lm.getChildCount() == 0 || state.getItemCount() == 0) {
return 0;
}
if (!lm.isSmoothScrollbarEnabled()) {
return state.getItemCount();
}
int firstVisiblePos = lm.findFirstVisibleItemPosition();
int lastVisiblePos = lm.findLastVisibleItemPosition();
// smooth scrollbar enabled. try to estimate better.
final int laidOutRange = Math.abs(firstVisiblePos - lastVisiblePos) + 1;
// estimate a size for full list.
return (int) ((float) getLaidOutArea() / laidOutRange * state.getItemCount());
}
示例3: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView recyclerView, RecyclerView.State state) {
final RecyclerView.ViewHolder holder = recyclerView.getChildViewHolder(view);
final Context context = recyclerView.getContext();
if(!registered) {
MaterialViewPagerHelper.registerRecyclerView(context, recyclerView);
registered = true;
}
int headerCells = 1;
//don't work with stagged
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if(layoutManager instanceof GridLayoutManager){
GridLayoutManager gridLayoutManager = (GridLayoutManager)layoutManager;
headerCells = gridLayoutManager.getSpanCount();
}
MaterialViewPagerAnimator animator = MaterialViewPagerHelper.getAnimator(context);
if (animator != null) {
if (holder.getAdapterPosition() < headerCells) {
outRect.top = Math.round(Utils.dpToPx(animator.getHeaderHeight() + 10, context));
}
}
}
示例4: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
int layoutOrientation = getOrientation(parent);
if (layoutOrientation == LinearLayoutManager.VERTICAL) {
outRect.top = 10;
outRect.left=5;
outRect.right=5;
} else if(layoutOrientation == LinearLayoutManager.HORIZONTAL) {
outRect.left = 5;
}
}
示例5: onDraw
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
super.onDraw(c, parent, state);
final int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
int position = parent.getChildLayoutPosition(child);
int column = (position + 1) % 3;
column = column == 0 ? mSpanCount : column;
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
.getLayoutParams();
final int top = child.getBottom() + params.bottomMargin +
Math.round(ViewCompat.getTranslationY(child));
final int bottom = top + mDivider.getIntrinsicHeight();
final int left = child.getRight() + params.rightMargin +
Math.round(ViewCompat.getTranslationX(child));
final int right = left + mDivider.getIntrinsicHeight();
mDivider.setBounds(child.getLeft(), top, right, bottom);
mDivider.draw(c);
if(column < mSpanCount) {
mDivider.setBounds(left, child.getTop(), right, bottom);
mDivider.draw(c);
}
}
}
示例6: assignSpans
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private void assignSpans(GridRangeStyle rangeStyle, RecyclerView.Recycler recycler, RecyclerView.State state, int count,
int consumedSpanCount, boolean layingOutInPrimaryDirection, LayoutManagerHelper helper) {
int span, spanDiff, start, end, diff;
// make sure we traverse from min position to max position
if (layingOutInPrimaryDirection) {
start = 0;
end = count;
diff = 1;
} else {
start = count - 1;
end = -1;
diff = -1;
}
if (helper.getOrientation() == VERTICAL && helper.isDoLayoutRTL()) { // start from last span
span = consumedSpanCount - 1;
spanDiff = -1;
} else {
span = 0;
spanDiff = 1;
}
for (int i = start; i != end; i += diff) {
View view = rangeStyle.mSet[i];
int spanSize = getSpanSize(rangeStyle.mSpanSizeLookup, recycler, state, helper.getPosition(view));
if (spanDiff == -1 && spanSize > 1) {
rangeStyle.mSpanIndices[i] = span - (spanSize - 1);
} else {
rangeStyle.mSpanIndices[i] = span;
}
span += spanDiff * spanSize;
}
}
示例7: fill
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* 填充方法
*
* @param recycler
* @param state
*/
private void fill(RecyclerView.Recycler recycler, RecyclerView.State state) {
if (getItemCount() <= 0 || state.isPreLayout()) {
return;
}
//考慮到當前RecyclerView會處於滑動的狀態,所以這裏的Rect的作用是展示當前顯示的區域
//需要考慮到RecyclerView的滑動量
//mHorizontalOffset 橫向的滑動偏移量
//mVerticalOffset 縱向的滑動偏移量
Rect displayRect = new Rect(0, mVerticalOffset,
getHorizontalSpace(),
getVerticalSpace() + mVerticalOffset);
/**
* 對這些View進行測量和布局操作
*/
for (int i = 0; i < getItemCount(); i++) {
Rect frame = mItemFrames.get(i);
if (Rect.intersects(displayRect, frame)) {
View scrap = recycler.getViewForPosition(i);
addView(scrap);
//測量子View
measureChildWithMargins(scrap, 0, 0);
//布局方法
layoutDecorated(scrap, frame.left - mHorizontalOffset, frame.top - mVerticalOffset,
frame.right - mHorizontalOffset, frame.bottom - mVerticalOffset);
}
}
}
示例8: onDraw
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
if (mOrientation == OrientationHelper.HORIZONTAL){
drawHorizontal(c,parent);
}else {
drawVertical(c,parent);
}
}
示例9: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
RecyclerView.State state) {
if (mOrientation == VERTICAL) {
outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
} else {
outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
}
}
示例10: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
if (mOrientation == VERTICAL_LIST) {
outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
} else {
outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
}
}
示例11: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
if (mOrientation == VERTICAL_LIST) {
outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
} else {
outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
}
}
示例12: smoothScrollToPosition
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state,
int position) {
View firstVisibleChild = recyclerView.getChildAt(0);
int itemHeight = firstVisibleChild.getHeight();
int currentPosition = recyclerView.getChildLayoutPosition(firstVisibleChild);
int distanceInPixels = Math.abs((currentPosition - position) * itemHeight);
if (distanceInPixels == 0) {
distanceInPixels = (int) Math.abs(firstVisibleChild.getY());
}
SmoothScroller smoothScroller = new SmoothScroller(recyclerView.getContext(), distanceInPixels, duration);
smoothScroller.setTargetPosition(position);
startSmoothScroll(smoothScroller);
}
示例13: onLayoutCompleted
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onLayoutCompleted(RecyclerView.State state) {
super.onLayoutCompleted(state);
mPendingScrollPosition = -1;
}
示例14: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
outRect.set(0, 0, 0, dividerHeight);
}
示例15: layoutDisappearingViews
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private void layoutDisappearingViews(
RecyclerView.Recycler recycler, RecyclerView.State state, int startTop) {
// TODO
}