本文整理汇总了Java中android.support.v7.widget.OrientationHelper.getDecoratedStart方法的典型用法代码示例。如果您正苦于以下问题:Java OrientationHelper.getDecoratedStart方法的具体用法?Java OrientationHelper.getDecoratedStart怎么用?Java OrientationHelper.getDecoratedStart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.widget.OrientationHelper
的用法示例。
在下文中一共展示了OrientationHelper.getDecoratedStart方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findEndView
import android.support.v7.widget.OrientationHelper; //导入方法依赖的package包/类
private View findEndView(RecyclerView.LayoutManager layoutManager, OrientationHelper helper) {
if (layoutManager instanceof LinearLayoutManager) {
int lastChild = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
if (lastChild == RecyclerView.NO_POSITION) {
return null;
}
View child = layoutManager.findViewByPosition(lastChild);
if (helper.getDecoratedStart(child) + helper.getDecoratedMeasurement(child) / 2
<= helper.getTotalSpace()) {
return child;
} else {
if (((LinearLayoutManager) layoutManager).findFirstCompletelyVisibleItemPosition() == 0) {
return null;
} else {
return layoutManager.findViewByPosition(lastChild - 1);
}
}
}
return super.findSnapView(layoutManager);
}
示例2: scrollToRightPositionWhenItemChanged
import android.support.v7.widget.OrientationHelper; //导入方法依赖的package包/类
/**
* 当item位置变换,滚动recycler到正确的位置
* TODO: 2017/2/21 0021 整理更优雅的写法 还有scrollToPosition(0)是否必要?
*/
private void scrollToRightPositionWhenItemChanged(RecyclerView recyclerView, View itemView, int itemPos) {
final RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManager instanceof ItemTouchHelper.ViewDropHandler) {
OrientationHelper helper = OrientationHelper.createVerticalHelper(layoutManager);
int start = helper.getDecoratedStart(itemView);
int end = helper.getDecoratedEnd(itemView);
((LinearLayoutManager) layoutManager).scrollToPositionWithOffset(
itemPos, lastItemPos > itemPos ? start : end - itemViewHeight);
// System.out.println(lastItemPos + "-" + childPos + "OrientationHelperOrientationHelper:"
// + height + "==" + itemViewHeight + "=||=" + start + "===" + end + "||||||" + myStart + "===" + itemTargetView.getHeight() );
}
if (lastItemPos == 0 || itemPos == 0) {
recyclerView.scrollToPosition(0);
}
}
示例3: findOneVisibleChild
import android.support.v7.widget.OrientationHelper; //导入方法依赖的package包/类
private View findOneVisibleChild(int fromIndex, int toIndex, boolean completelyVisible,
boolean acceptPartiallyVisible) {
OrientationHelper helper;
if (layoutManager.canScrollVertically()) {
helper = OrientationHelper.createVerticalHelper(layoutManager);
} else {
helper = OrientationHelper.createHorizontalHelper(layoutManager);
}
final int start = helper.getStartAfterPadding();
final int end = helper.getEndAfterPadding();
final int next = toIndex > fromIndex ? 1 : -1;
View partiallyVisible = null;
for (int i = fromIndex; i != toIndex; i += next) {
final View child = layoutManager.getChildAt(i);
final int childStart = helper.getDecoratedStart(child);
final int childEnd = helper.getDecoratedEnd(child);
if (childStart < end && childEnd > start) {
if (completelyVisible) {
if (childStart >= start && childEnd <= end) {
return child;
} else if (acceptPartiallyVisible && partiallyVisible == null) {
partiallyVisible = child;
}
} else {
return child;
}
}
}
return partiallyVisible;
}
示例4: distanceToStart
import android.support.v7.widget.OrientationHelper; //导入方法依赖的package包/类
private int distanceToStart(View targetView, OrientationHelper helper, boolean fromEnd) {
if (isRtlHorizontal && !fromEnd) {
return distanceToEnd(targetView, helper, true);
}
return helper.getDecoratedStart(targetView) - helper.getStartAfterPadding();
}
示例5: distanceToStart
import android.support.v7.widget.OrientationHelper; //导入方法依赖的package包/类
private int distanceToStart(View targetView, OrientationHelper helper, boolean fromEnd) {
if (mIsRtlHorizontal && !fromEnd) {
return distanceToEnd(targetView, helper, true);
}
return helper.getDecoratedStart(targetView) - helper.getStartAfterPadding();
}
示例6: computeAlignOffset
import android.support.v7.widget.OrientationHelper; //导入方法依赖的package包/类
@Override
public int computeAlignOffset(int offset, boolean isLayoutEnd,
boolean useAnchor, LayoutManagerHelper helper) {
final boolean layoutInVertical = helper.getOrientation() == VERTICAL;
final OrientationHelper orientationHelper = helper.getMainOrientationHelper();
final View child = helper.findViewByPosition(offset + getRange().getLower());
if (child == null) {
return 0;
}
if (layoutInVertical) {
// in middle nothing need to do
if (isLayoutEnd) {
if (offset == getItemCount() - 1) {
//the last item may not have the largest bottom, so calculate gaps between last items in every lane
return mMarginBottom + mPaddingBottom + (getMaxEnd(orientationHelper.getDecoratedEnd(child),
orientationHelper) - orientationHelper.getDecoratedEnd(child));
} else if (!useAnchor) {
final int minEnd = getMinEnd(orientationHelper.getDecoratedStart(child), orientationHelper);
return minEnd - orientationHelper.getDecoratedEnd(child);
}
} else {
if (offset == 0) {
//the first item may not have the smallest top, so calculate gaps between first items in every lane
return -mMarginTop - mPaddingTop - (orientationHelper.getDecoratedStart(child) - getMinStart(
orientationHelper.getDecoratedStart(child), orientationHelper));
} else if (!useAnchor) {
final int maxStart = getMaxStart(orientationHelper.getDecoratedEnd(child), orientationHelper);
return maxStart - orientationHelper.getDecoratedStart(child);
}
}
} else {
}
return 0;
}
示例7: calculateCachedStart
import android.support.v7.widget.OrientationHelper; //导入方法依赖的package包/类
void calculateCachedStart(@NonNull OrientationHelper helper) {
if (mViews.size() == 0) {
mCachedStart = INVALID_LINE;
} else {
final View startView = mViews.get(0);
mCachedStart = helper.getDecoratedStart(startView);
}
}
示例8: isEmpty
import android.support.v7.widget.OrientationHelper; //导入方法依赖的package包/类
/**
* Returns if there is no child between start-end lines
*
* @param start The start line
* @param end The end line
* @return true if a new child can be added between start and end
*/
boolean isEmpty(int start, int end, OrientationHelper orientationHelper) {
final int count = mViews.size();
for (int i = 0; i < count; i++) {
final View view = mViews.get(i);
if (orientationHelper.getDecoratedStart(view) < end &&
orientationHelper.getDecoratedEnd(view) > start) {
return false;
}
}
return true;
}
示例9: findEndView
import android.support.v7.widget.OrientationHelper; //导入方法依赖的package包/类
private View findEndView(RecyclerView.LayoutManager layoutManager,
OrientationHelper helper) {
if (layoutManager instanceof LinearLayoutManager) {
int lastChild = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
if (lastChild == RecyclerView.NO_POSITION) {
return null;
}
View child = layoutManager.findViewByPosition(lastChild);
float visibleWidth;
if (mIsRtlHorizontal) {
visibleWidth = (float) helper.getDecoratedEnd(child)
/ helper.getDecoratedMeasurement(child);
} else {
visibleWidth = (float) (helper.getTotalSpace() - helper.getDecoratedStart(child))
/ helper.getDecoratedMeasurement(child);
}
// If we're at the start of the list, we shouldn't snap
// to avoid having the first item not completely visible.
boolean startOfList = ((LinearLayoutManager) layoutManager)
.findFirstCompletelyVisibleItemPosition() == 0;
if (visibleWidth > 0.5f && !startOfList) {
return child;
} else if (mSnapLastItemEnabled && startOfList) {
return child;
} else if (startOfList) {
return null;
} else {
// If the child wasn't returned, we need to return the previous view
return layoutManager.findViewByPosition(lastChild - 1);
}
}
return null;
}
示例10: findCenterView
import android.support.v7.widget.OrientationHelper; //导入方法依赖的package包/类
/**
* Return the child view that is currently closest to the center of this parent.
*
* @param layoutManager The {@link RecyclerView.LayoutManager} associated with the attached
* {@link RecyclerView}.
* @param helper The relevant {@link OrientationHelper} for the attached {@link RecyclerView}.
* @return the child view that is currently closest to the center of this parent.
*/
@Nullable
private View findCenterView(RecyclerView.LayoutManager layoutManager,
OrientationHelper helper) {
int childCount = layoutManager.getChildCount();
if (childCount == 0) {
return null;
}
View closestChild = null;
final int center;
if (layoutManager.getClipToPadding()) {
center = helper.getStartAfterPadding() + helper.getTotalSpace() / 2;
} else {
center = helper.getEnd() / 2;
}
int absClosest = Integer.MAX_VALUE;
for (int i = 0; i < childCount; i++) {
final View child = layoutManager.getChildAt(i);
final int childMonthIndex = layoutManager.getPosition(child) % ITEM_PER_MONTH;
if (childMonthIndex != ITEM_PER_MONTH / 2) {
i += ITEM_PER_MONTH * (childMonthIndex > ITEM_PER_MONTH / 2 ? 1.5f : 0.5f) - childMonthIndex - 1;
continue;
}
int childCenter = helper.getDecoratedStart(child)
+ (helper.getDecoratedMeasurement(child) / 2);
int absDistance = Math.abs(childCenter - center);
// if child center is closer than previous closest, set it as closest
if (absDistance < absClosest) {
absClosest = absDistance;
closestChild = child;
}
}
return closestChild;
}
示例11: findStartView
import android.support.v7.widget.OrientationHelper; //导入方法依赖的package包/类
/**
* Returns the first view that we should snap to.
*
* @param layoutManager the recyclerview's layout manager
* @param helper orientation helper to calculate view sizes
* @return the first view in the LayoutManager to snap to
*/
private View findStartView(RecyclerView.LayoutManager layoutManager,
OrientationHelper helper) {
if (layoutManager instanceof LinearLayoutManager) {
int firstChild = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
if (firstChild == RecyclerView.NO_POSITION) {
return null;
}
View child = layoutManager.findViewByPosition(firstChild);
float visibleWidth;
// We should return the child if it's visible width
// is greater than 0.5 of it's total width.
// In a RTL configuration, we need to check the start point and in LTR the end point
if (isRtlHorizontal) {
visibleWidth = (float) (helper.getTotalSpace() - helper.getDecoratedStart(child))
/ helper.getDecoratedMeasurement(child);
} else {
visibleWidth = (float) helper.getDecoratedEnd(child)
/ helper.getDecoratedMeasurement(child);
}
// If we're at the end of the list, we shouldn't snap
// to avoid having the last item not completely visible.
boolean endOfList = ((LinearLayoutManager) layoutManager)
.findLastCompletelyVisibleItemPosition()
== layoutManager.getItemCount() - 1;
if (visibleWidth > 0.5f && !endOfList) {
return child;
} else if (snapLastItem && endOfList) {
return child;
} else if (endOfList) {
return null;
} else {
// If the child wasn't returned, we need to return
// the next view close to the start.
return layoutManager.findViewByPosition(firstChild + 1);
}
}
return null;
}
示例12: findSnapView
import android.support.v7.widget.OrientationHelper; //导入方法依赖的package包/类
@Override
View findSnapView(RecyclerView.LayoutManager layoutManager) {
OrientationHelper helper = layoutManager.canScrollHorizontally()
? OrientationHelper.createHorizontalHelper(layoutManager)
: OrientationHelper.createVerticalHelper(layoutManager);
int childCount = layoutManager.getChildCount();
if (childCount == 0) return null;
View closestChild = null;
int closestPosition = RecyclerView.NO_POSITION;
final int containerPosition = getContainerPosition(layoutManager, helper);
int absClosest = Integer.MAX_VALUE;
for (int i = 0; i < childCount; i++) {
final View child = layoutManager.getChildAt(i);
int childPosition = getChildPosition(child, helper);
int absDistance = Math.abs(childPosition - containerPosition);
if (helper.getDecoratedStart(child) == 0
&& previousClosestPosition != 0
&& layoutManager.getPosition(child) == 0) {
//RecyclerView reached start
closestChild = child;
closestPosition = layoutManager.getPosition(closestChild);
break;
}
if (helper.getDecoratedEnd(child) == helper.getTotalSpace()
&& previousClosestPosition != layoutManager.getItemCount() - 1
&& layoutManager.getPosition(child) == layoutManager.getItemCount() - 1) {
//RecyclerView reached end
closestChild = child;
closestPosition = layoutManager.getPosition(closestChild);
break;
}
if (previousClosestPosition == layoutManager.getPosition(child) && getDistance(layoutManager, child, helper) == 0) {
//child is already set to the position.
closestChild = child;
break;
}
if (layoutManager.getPosition(child) % snapCount != 0) {
continue;
}
if (absDistance < absClosest) {
absClosest = absDistance;
closestChild = child;
closestPosition = layoutManager.getPosition(closestChild);
}
}
previousClosestPosition = closestPosition == RecyclerView.NO_POSITION ? previousClosestPosition : closestPosition;
isNoOffset = getDistance(layoutManager, closestChild, helper) == 0;
if (listener != null && closestPosition != RecyclerView.NO_POSITION) {
listener.snapped(closestPosition);
}
return closestChild;
}
示例13: distanceToEnd
import android.support.v7.widget.OrientationHelper; //导入方法依赖的package包/类
private int distanceToEnd(View targetView, OrientationHelper helper) {
if (mIsRtl) {
return helper.getDecoratedStart(targetView) - helper.getStartAfterPadding();
}
return helper.getDecoratedEnd(targetView) - helper.getEndAfterPadding();
}
示例14: findEndView
import android.support.v7.widget.OrientationHelper; //导入方法依赖的package包/类
private View findEndView(RecyclerView.LayoutManager layoutManager,
OrientationHelper helper) {
if (layoutManager instanceof LinearLayoutManager) {
int lastChild = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
int offset = 1;
if (layoutManager instanceof GridLayoutManager) {
offset += ((GridLayoutManager) layoutManager).getSpanCount() - 1;
}
if (lastChild == RecyclerView.NO_POSITION) {
return null;
}
View child = layoutManager.findViewByPosition(lastChild);
float visibleWidth;
if (isRtlHorizontal) {
visibleWidth = (float) helper.getDecoratedEnd(child)
/ helper.getDecoratedMeasurement(child);
} else {
visibleWidth = (float) (helper.getTotalSpace() - helper.getDecoratedStart(child))
/ helper.getDecoratedMeasurement(child);
}
// If we're at the start of the list, we shouldn't snap
// to avoid having the first item not completely visible.
boolean startOfList = ((LinearLayoutManager) layoutManager)
.findFirstCompletelyVisibleItemPosition() == 0;
if (visibleWidth > 0.5f && !startOfList) {
return child;
} else if (snapLastItem && startOfList) {
return child;
} else if (startOfList) {
return null;
} else {
// If the child wasn't returned, we need to return the previous view
return layoutManager.findViewByPosition(lastChild - offset);
}
}
return null;
}
示例15: findStartView
import android.support.v7.widget.OrientationHelper; //导入方法依赖的package包/类
/**
* Returns the first view that we should snap to.
*
* @param layoutManager the recyclerview's layout manager
* @param helper orientation helper to calculate view sizes
* @return the first view in the LayoutManager to snap to
*/
private View findStartView(RecyclerView.LayoutManager layoutManager,
OrientationHelper helper) {
if (layoutManager instanceof LinearLayoutManager) {
int firstChild = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
int offset = 1;
if (layoutManager instanceof GridLayoutManager) {
offset += ((GridLayoutManager) layoutManager).getSpanCount() - 1;
}
if (firstChild == RecyclerView.NO_POSITION) {
return null;
}
View child = layoutManager.findViewByPosition(firstChild);
float visibleWidth;
// We should return the child if it's visible width
// is greater than 0.5 of it's total width.
// In a RTL configuration, we need to check the start point and in LTR the end point
if (isRtlHorizontal) {
visibleWidth = (float) (helper.getTotalSpace() - helper.getDecoratedStart(child))
/ helper.getDecoratedMeasurement(child);
} else {
visibleWidth = (float) helper.getDecoratedEnd(child)
/ helper.getDecoratedMeasurement(child);
}
// If we're at the end of the list, we shouldn't snap
// to avoid having the last item not completely visible.
boolean endOfList = ((LinearLayoutManager) layoutManager)
.findLastCompletelyVisibleItemPosition()
== layoutManager.getItemCount() - 1;
if (visibleWidth > 0.5f && !endOfList) {
return child;
} else if (snapLastItem && endOfList) {
return child;
} else if (endOfList) {
return null;
} else {
// If the child wasn't returned, we need to return
// the next view close to the start.
return layoutManager.findViewByPosition(firstChild + offset);
}
}
return null;
}