当前位置: 首页>>代码示例>>Java>>正文


Java OrientationHelper.getTotalSpace方法代码示例

本文整理汇总了Java中android.support.v7.widget.OrientationHelper.getTotalSpace方法的典型用法代码示例。如果您正苦于以下问题:Java OrientationHelper.getTotalSpace方法的具体用法?Java OrientationHelper.getTotalSpace怎么用?Java OrientationHelper.getTotalSpace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v7.widget.OrientationHelper的用法示例。


在下文中一共展示了OrientationHelper.getTotalSpace方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
  }
 
开发者ID:liuguoquan727,项目名称:android-study,代码行数:26,代码来源:GravitySnapHelper.java

示例2: 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 (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 - 1);
        }
    }
    return null;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:41,代码来源:GravityDelegate.java

示例3: 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;
}
 
开发者ID:mangoblogger,项目名称:MangoBloggerAndroidApp,代码行数:41,代码来源:GravitySnapHelper.java

示例4: 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;
}
 
开发者ID:thaihuynhxyz,项目名称:recycler-view-calendar,代码行数:45,代码来源:CalendarSnapHelper.java

示例5: 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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:54,代码来源:GravityDelegate.java

示例6: 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;
}
 
开发者ID:aliumujib,项目名称:Orin,代码行数:59,代码来源:GravityDelegate.java

示例7: 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;
}
 
开发者ID:aliumujib,项目名称:Orin,代码行数:46,代码来源:GravityDelegate.java

示例8: 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;
}
 
开发者ID:TakuSemba,项目名称:MultiSnapRecyclerView,代码行数:55,代码来源:SnapHelperDelegator.java

示例9: getContainerPosition

import android.support.v7.widget.OrientationHelper; //导入方法依赖的package包/类
@Override
int getContainerPosition(RecyclerView.LayoutManager layoutManager, OrientationHelper helper) {
    return layoutManager.getClipToPadding()
            ? helper.getStartAfterPadding() + helper.getTotalSpace() / 2
            : helper.getEnd() / 2;
}
 
开发者ID:TakuSemba,项目名称:MultiSnapRecyclerView,代码行数:7,代码来源:CenterSnapHelperDelegator.java

示例10: getContainerPosition

import android.support.v7.widget.OrientationHelper; //导入方法依赖的package包/类
@Override
int getContainerPosition(RecyclerView.LayoutManager layoutManager, OrientationHelper helper) {
    return layoutManager.getClipToPadding()
            ? helper.getStartAfterPadding() + helper.getTotalSpace()
            : helper.getEnd() - helper.getEndPadding();
}
 
开发者ID:TakuSemba,项目名称:MultiSnapRecyclerView,代码行数:7,代码来源:EndSnapHelperDelegator.java

示例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 (mIsRtlHorizontal) {
            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 (mSnapLastItemEnabled && 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;
}
 
开发者ID:mangoblogger,项目名称:MangoBloggerAndroidApp,代码行数:54,代码来源:GravitySnapHelper.java


注:本文中的android.support.v7.widget.OrientationHelper.getTotalSpace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。