本文整理匯總了Java中android.support.v7.widget.RecyclerView.getChildPosition方法的典型用法代碼示例。如果您正苦於以下問題:Java RecyclerView.getChildPosition方法的具體用法?Java RecyclerView.getChildPosition怎麽用?Java RecyclerView.getChildPosition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v7.widget.RecyclerView
的用法示例。
在下文中一共展示了RecyclerView.getChildPosition方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
final int totalSpanCount = getSpanCount(parent);
final int itemPosition = parent.getChildPosition(view);
final boolean isLeft = isLeft(view, totalSpanCount);
final boolean isRight = isRight(view, totalSpanCount);
final boolean isFull = isFull(view, totalSpanCount);
final boolean isCenter = !isLeft && !isRight && !isFull;
final boolean isTop = isTop(parent, itemPosition, totalSpanCount);
final boolean isBottom = isBottom(parent, itemPosition, totalSpanCount);
// LogUtil.d(itemPosition, "total:"+totalSpanCount, "index:"+getSpanIndex(view), "Size:"+getSpanSize(view), isLeft, isTop, isRight, isBottom, isFull, isCenter);
final int left = (isRight || isCenter) ? mHalfSpacingWidth : 0;
final int right = (isLeft || isCenter) ? mHalfSpacingWidth : 0;
final int top = !isTop ? mHalfSpacingHeight : 0;
final int bottom = !isBottom ? mHalfSpacingHeight : 0;
outRect.set(left, top, right, bottom);
}
示例2: 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);
if (mDivider == null) {
return;
}
if (parent.getChildPosition(view) < 1) {
return;
}
if (getOrientation(parent) == LinearLayoutManager.VERTICAL) {
outRect.top = mDivider.getIntrinsicHeight();
} else {
outRect.left = mDivider.getIntrinsicWidth();
}
}
示例3: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
if (mFirstSpace != 0) {
if (0 == parent.getChildPosition(view)) {
if (LinearLayoutManager.HORIZONTAL == mScroller.getOrientation()) {
outRect.left = mFirstSpace;
} else {
outRect.top = mFirstSpace;
}
}
}
if (mLastSpace != 0) {
View nativeView = mScroller.getNativeView();
ScrollerImp s;
if (nativeView instanceof ScrollerStickyParent) {
s = (ScrollerImp)((ScrollerStickyParent)nativeView).getChildAt(0);
} else {
s = (ScrollerImp)mScroller.getNativeView();
}
RecyclerView.Adapter adapter = s.getAdapter();
if (null != adapter) {
int count = adapter.getItemCount();
if ((count - 1) == parent.getChildPosition(view)) {
if (LinearLayoutManager.HORIZONTAL == mScroller.getOrientation()) {
outRect.right = mLastSpace;
} else {
outRect.bottom = mLastSpace;
}
}
}
}
}
示例4: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view,
RecyclerView parent, RecyclerView.State state) {
if (parent.getChildPosition(view) != parent.getAdapter().getItemCount() - 1)
outRect.right = space;
if (parent.getChildPosition(view) != 0)
outRect.left = space;
}
示例5: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
// Add top margin only for the first item to avoid double space between items
if(parent.getChildPosition(view) != 0)
outRect.left = space;
}
示例6: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
if(parent.getChildPosition(view)!=0){
outRect.top = space;
}
}
示例7: updatePosBasedOnReferenceList
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private void updatePosBasedOnReferenceList(RecyclerView referenceRv) {
View firstVisibleView = referenceRv.getChildAt(0);
int actual = referenceRv.getChildPosition(firstVisibleView);
((LinearLayoutManager) indexList.getLayoutManager()).scrollToPositionWithOffset(actual, firstVisibleView.getTop() + 0);
}
示例8: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView rv, RecyclerView.State state) {
super.getItemOffsets(outRect, view, rv, state);
debugLog("getItemOffsets");
debugLog("View top = " + view.getTop());
if (selectedDragItemPos != -1) {
int itemPos = rv.getChildPosition(view);
debugLog("itemPos =" + itemPos);
if (!canDragOver(itemPos)) {
return;
}
if (itemPos == selectedDragItemPos) {
view.setVisibility(View.INVISIBLE);
} else {
//Make view visible incase invisible
view.setVisibility(View.VISIBLE);
//Find middle of the floatingItem
float floatMiddleY = floatingItemBounds.top + floatingItemBounds.height() / 2;
//Moving down the list
//These will auto-animate if the device continually sends touch motion events
// if (totalMovment>0)
{
if ((itemPos > selectedDragItemPos) && (view.getTop() < floatMiddleY)) {
float amountUp = (floatMiddleY - view.getTop()) / (float) view.getHeight();
// amountUp *= 0.5f;
if (amountUp > 1)
amountUp = 1;
outRect.top = -(int) (floatingItemBounds.height() * amountUp);
outRect.bottom = (int) (floatingItemBounds.height() * amountUp);
}
}//Moving up the list
// else if (totalMovment < 0)
{
if ((itemPos < selectedDragItemPos) && (view.getBottom() > floatMiddleY)) {
float amountDown = ((float) view.getBottom() - floatMiddleY) / (float) view.getHeight();
// amountDown *= 0.5f;
if (amountDown > 1)
amountDown = 1;
outRect.top = (int) (floatingItemBounds.height() * amountDown);
outRect.bottom = -(int) (floatingItemBounds.height() * amountDown);
}
}
}
} else {
outRect.top = 0;
outRect.bottom = 0;
//Make view visible incase invisible
view.setVisibility(View.VISIBLE);
}
}
示例9: getNewPostion
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* Find the new position by scanning through the items on
* screen and finding the positional relationship.
* This *seems* to work, another method would be to use
* getItemOffsets, but I think that could miss items?..
*/
private int getNewPostion(RecyclerView rv) {
int itemsOnScreen = rv.getLayoutManager().getChildCount();
float floatMiddleY = floatingItemBounds.top + floatingItemBounds.height() / 2;
int above = 0;
int below = Integer.MAX_VALUE;
for (int n = 0; n < itemsOnScreen; n++) //Scan though items on screen, however they may not
{ // be in order!
View view = rv.getLayoutManager().getChildAt(n);
if (view.getVisibility() != View.VISIBLE)
continue;
int itemPos = rv.getChildPosition(view);
if (itemPos == selectedDragItemPos) //Don't check against itself!
continue;
float viewMiddleY = view.getTop() + view.getHeight() / 2;
if (floatMiddleY > viewMiddleY) //Is above this item
{
if (itemPos > above)
above = itemPos;
} else if (floatMiddleY <= viewMiddleY && itemPos < below) //Is below this item
{
below = itemPos;
}
}
debugLog("above = " + above + " below = " + below);
if (below != Integer.MAX_VALUE) {
if (below < selectedDragItemPos) //Need to count itself
below++;
return below - 1;
} else {
if (above < selectedDragItemPos)
above++;
return above;
}
}
示例10: 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) {
String TAG = "DragSortRecycler";
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.getChildPosition(itemView);
debugLog("selectedDragItemPos = " + selectedDragItemPos);
return true;
}
}
return false;
}