本文整理匯總了Java中android.support.v7.widget.RecyclerView.getChildLayoutPosition方法的典型用法代碼示例。如果您正苦於以下問題:Java RecyclerView.getChildLayoutPosition方法的具體用法?Java RecyclerView.getChildLayoutPosition怎麽用?Java RecyclerView.getChildLayoutPosition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v7.widget.RecyclerView
的用法示例。
在下文中一共展示了RecyclerView.getChildLayoutPosition方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
int spanCount = ((GridLayoutManager) parent.getLayoutManager()).getSpanCount();
int orientation = ((GridLayoutManager)parent.getLayoutManager()).getOrientation();
int position = parent.getChildLayoutPosition(view);
if(orientation == OrientationHelper.VERTICAL && (position + 1) % spanCount == 0) {
outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
return;
}
if(orientation == OrientationHelper.HORIZONTAL && (position + 1) % spanCount == 0) {
outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
return;
}
outRect.set(0, 0, mDivider.getIntrinsicWidth(), mDivider.getIntrinsicHeight());
}
示例2: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
if (dividerDrawable == null) {
return;
}
if (parent.getChildLayoutPosition(view) < 1) {
return;
}
if (orientation == LinearLayoutManager.VERTICAL) {
outRect.top = dividerDrawable.getIntrinsicHeight();
} else if (orientation == LinearLayoutManager.HORIZONTAL) {
outRect.left = dividerDrawable.getIntrinsicWidth();
}
}
示例3: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
if(spanSizeLookup == null){
GridLayoutManager layoutManager = (GridLayoutManager) parent.getLayoutManager();
spanSizeLookup = layoutManager.getSpanSizeLookup();
}
int spanSize = spanSizeLookup.getSpanSize(parent.getChildLayoutPosition(view));
if( spanSize == 2){
if(firstPosition == -1){
firstPosition = parent.getChildLayoutPosition(view);
}
if((parent.getChildLayoutPosition(view) - firstPosition) % 2 == 0){
outRect.right = space/2;
outRect.top = space;
}
else{
outRect.left = space/2;
outRect.top = space;
}
}
}
示例4: drawVertical
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
public void drawVertical(Canvas c, RecyclerView parent) {
final int left = parent.getPaddingLeft();
final int right = parent.getWidth() - parent.getPaddingRight();
final int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
// 有腳部時,最後一條不畫
if (hasFooter &&
parent.getChildLayoutPosition(child) == parent.getLayoutManager().getItemCount() - 1) {
continue;
}
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
.getLayoutParams();
final int top = child.getBottom() + params.bottomMargin;
final int bottom = top + mDivider.getIntrinsicHeight();
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(c);
}
}
示例5: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
if (dividerDrawable == null) {
return;
}
//如果是第一個item,不需要divider,所以直接return
if (parent.getChildLayoutPosition(view) < 1) {
return;
}
//相當於給itemView設置margin,給divider預留空間
if (orientation == LinearLayoutManager.VERTICAL) {
outRect.top = dividerDrawable.getIntrinsicHeight();
} else if (orientation == LinearLayoutManager.HORIZONTAL) {
outRect.left = dividerDrawable.getIntrinsicWidth();
}
}
示例6: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* Set different margins for the items inside the recyclerView: no top margin for the first row
* and no left margin for the first column.
*/
@Override
public void getItemOffsets(Rect outRect, View view,
RecyclerView parent, RecyclerView.State state) {
int position = parent.getChildLayoutPosition(view);
//set right margin to all
outRect.right = margin;
//set bottom margin to all
outRect.bottom = margin / 4;
//we only add top margin to the first row
if (position < columns) {
outRect.top = margin / 4;
}
//add left margin only to the first column
if (position % columns == 0) {
outRect.left = margin;
}
}
示例7: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
int pos = parent.getChildLayoutPosition(view);
int halfPadding = Math.abs(Defaults.DIVIDER_WIDTH / 2);
int fullPadding = 2 * halfPadding;
outRect.top = (pos < Defaults.GRID_SIZE) ? 0 : fullPadding;
if (pos % Defaults.GRID_SIZE == 0) { // first column items
outRect.left = 0;
outRect.right = halfPadding;
} else if ( ((pos + 1) % Defaults.GRID_SIZE) == 0 ) { // last column items
outRect.right = 0;
outRect.left = halfPadding;
} else { // middle columns items
outRect.left = halfPadding;
outRect.right = halfPadding;
}
outRect.bottom = 0;
}
示例8: 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);
}
示例9: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
super.getItemOffsets(outRect, view, parent, state);
int value = (parent.getChildLayoutPosition(view) < mNumberOfChildren) ? mHeaderHeight : 0;
if (mReversed) {
outRect.bottom = value;
} else {
outRect.top = value;
}
}
示例10: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view,
RecyclerView parent, RecyclerView.State state) {
outRect.left = space;
outRect.right = space;
outRect.bottom = space;
//outRect.top = space;
// Add top margin only for the first item to avoid double space between items
if (parent.getChildLayoutPosition(view) < 3) {
outRect.top = space;
} else {
outRect.top = 0;
}
}
示例11: canTriggerLoadMore
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
public boolean canTriggerLoadMore(RecyclerView recyclerView) {
View lastChild = recyclerView.getChildAt(recyclerView.getChildCount() - 1);
int position = recyclerView.getChildLayoutPosition(lastChild);
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
int totalItemCount = layoutManager.getItemCount();
return totalItemCount - 1 == position;
}
示例12: 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);
}
}
}
示例13: 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);
}
示例14: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
if (outRect == null || parent == null) {
return;
}
int pos = parent.getChildLayoutPosition(view);
outRect.right = mSpace;
outRect.left = mSpace;
if (pos >= mSpanCount) {
outRect.top = mSpace * 2;
}
}
示例15: onInterceptTouchEvent
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
debugLog("onInterceptTouchEvent");
//if (e.getAction() == MotionEvent.ACTION_DOWN)
{
View itemView = rv.findChildViewUnder(e.getX(), e.getY());
if (itemView == null)
return false;
boolean dragging = false;
if ((dragHandleWidth > 0) && (e.getX() < dragHandleWidth)) {
dragging = true;
} else if (viewHandleId != -1) {
//Find the handle in the list item
View handleView = itemView.findViewById(viewHandleId);
if (handleView == null) {
Log.e(TAG, "The view ID " + viewHandleId + " was not found in the RecycleView item");
return false;
}
//View should be visible to drag
if (handleView.getVisibility() != View.VISIBLE) {
return false;
}
//We need to find the relative position of the handle to the parent view
//Then we can work out if the touch is within the handle
int[] parentItemPos = new int[2];
itemView.getLocationInWindow(parentItemPos);
int[] handlePos = new int[2];
handleView.getLocationInWindow(handlePos);
int xRel = handlePos[0] - parentItemPos[0];
int yRel = handlePos[1] - parentItemPos[1];
Rect touchBounds = new Rect(itemView.getLeft() + xRel, itemView.getTop() + yRel,
itemView.getLeft() + xRel + handleView.getWidth(),
itemView.getTop() + yRel + handleView.getHeight()
);
if (touchBounds.contains((int) e.getX(), (int) e.getY()))
dragging = true;
debugLog("parentItemPos = " + parentItemPos[0] + " " + parentItemPos[1]);
debugLog("handlePos = " + handlePos[0] + " " + handlePos[1]);
}
if (dragging) {
debugLog("Started Drag");
setIsDragging(true);
floatingItem = createFloatingBitmap(itemView);
fingerAnchorY = (int) e.getY();
fingerOffsetInViewY = fingerAnchorY - itemView.getTop();
fingerY = fingerAnchorY;
selectedDragItemPos = rv.getChildLayoutPosition(itemView);
debugLog("selectedDragItemPos = " + selectedDragItemPos);
return true;
}
}
return false;
}