android.view.View#resolveSize ( )源码实例Demo

下面列出了android.view.View#resolveSize ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    int childCount = getChildCount();
    if (childCount > 1) {
        throw new IllegalStateException("SwipeBackLayout must contains only one direct child.");
    }
    int defaultMeasuredWidth = 0;
    int defaultMeasuredHeight = 0;
    int measuredWidth;
    int measuredHeight;
    if (childCount > 0) {
        measureChildren(widthMeasureSpec, heightMeasureSpec);
        mDragContentView = getChildAt(0);
        defaultMeasuredWidth = mDragContentView.getMeasuredWidth();
        defaultMeasuredHeight = mDragContentView.getMeasuredHeight();
    }
    measuredWidth = View.resolveSize(defaultMeasuredWidth, widthMeasureSpec) + getPaddingLeft() + getPaddingRight();
    measuredHeight = View.resolveSize(defaultMeasuredHeight, heightMeasureSpec) + getPaddingTop() + getPaddingBottom();

    setMeasuredDimension(measuredWidth, measuredHeight);
}
 
源代码2 项目: CSipSimple   文件: Utility4.java
@Override
public int resolveSizeAndState(int size, int measureSpec, int state) {
    return View.resolveSize(size, measureSpec);
}
 
源代码3 项目: JD-Test   文件: PercentAspectRatioMeasure.java
/**
 * Updates the given measure spec with respect to the aspect ratio.
 *
 * <p>Note: Measure spec is not changed if the aspect ratio is not greater than zero or if
 * layoutParams is null.
 *
 * <p>Measure spec of the layout dimension (width or height) specified as "0dp" is updated
 * to match the measure spec of the other dimension adjusted by the aspect ratio. Exactly one
 * layout dimension should be specified as "0dp".
 *
 * <p>Padding is taken into account so that the aspect ratio refers to the content without
 * padding: {@code aspectRatio == (viewWidth - widthPadding) / (viewHeight - heightPadding)}
 *
 * <p>Updated measure spec respects the parent's constraints. I.e. measure spec is not changed
 * if the parent has specified mode {@code EXACTLY}, and it doesn't exceed measure size if parent
 * has specified mode {@code AT_MOST}.
 *
 * @param spec in/out measure spec to be updated
 * @param aspectRatio desired aspect ratio
 * @param layoutParams view's layout params
 * @param widthPadding view's left + right padding
 * @param heightPadding view's top + bottom padding
 */
public static void updateMeasureSpec(
        Spec spec,
        float aspectRatio,
        @Nullable ViewGroup.LayoutParams layoutParams,
        int widthPadding,
        int heightPadding) {
    if (aspectRatio <= 0 || layoutParams == null) {
        return;
    }
    if (shouldAdjust(layoutParams.height)) {
        int widthSpecSize = View.MeasureSpec.getSize(spec.width);
        int desiredHeight = (int) ((widthSpecSize - widthPadding) / aspectRatio + heightPadding);
        int resolvedHeight = View.resolveSize(desiredHeight, spec.height);
        spec.height = View.MeasureSpec.makeMeasureSpec(resolvedHeight, View.MeasureSpec.EXACTLY);
    } else if (shouldAdjust(layoutParams.width)) {
        int heightSpecSize = View.MeasureSpec.getSize(spec.height);
        int desiredWidth = (int) ((heightSpecSize - heightPadding) * aspectRatio + widthPadding);
        int resolvedWidth = View.resolveSize(desiredWidth, spec.width);
        spec.width = View.MeasureSpec.makeMeasureSpec(resolvedWidth, View.MeasureSpec.EXACTLY);
    }
}
 
源代码4 项目: JD-Test   文件: BannerAspectRatioMeasure.java
/**
 * Updates the given measure spec with respect to the aspect ratio.
 *
 * <p>Note: Measure spec is not changed if the aspect ratio is not greater than zero or if
 * layoutParams is null.
 *
 * <p>Measure spec of the layout dimension (width or height) specified as "0dp" is updated
 * to match the measure spec of the other dimension adjusted by the aspect ratio. Exactly one
 * layout dimension should be specified as "0dp".
 *
 * <p>Padding is taken into account so that the aspect ratio refers to the content without
 * padding: {@code aspectRatio == (viewWidth - widthPadding) / (viewHeight - heightPadding)}
 *
 * <p>Updated measure spec respects the parent's constraints. I.e. measure spec is not changed
 * if the parent has specified mode {@code EXACTLY}, and it doesn't exceed measure size if parent
 * has specified mode {@code AT_MOST}.
 *
 * @param spec in/out measure spec to be updated
 * @param aspectRatio desired aspect ratio
 * @param layoutParams view's layout params
 * @param widthPadding view's left + right padding
 * @param heightPadding view's top + bottom padding
 */
public static void updateMeasureSpec(
        Spec spec,
        float aspectRatio,
        @Nullable ViewGroup.LayoutParams layoutParams,
        int widthPadding,
        int heightPadding) {
    if (aspectRatio <= 0 || layoutParams == null) {
        return;
    }
    if (shouldAdjust(layoutParams.height)) {
        int widthSpecSize = View.MeasureSpec.getSize(spec.width);
        int desiredHeight = (int) ((widthSpecSize - widthPadding) / aspectRatio + heightPadding);
        int resolvedHeight = View.resolveSize(desiredHeight, spec.height);
        spec.height = View.MeasureSpec.makeMeasureSpec(resolvedHeight, View.MeasureSpec.EXACTLY);
    } else if (shouldAdjust(layoutParams.width)) {
        int heightSpecSize = View.MeasureSpec.getSize(spec.height);
        int desiredWidth = (int) ((heightSpecSize - heightPadding) * aspectRatio + widthPadding);
        int resolvedWidth = View.resolveSize(desiredWidth, spec.width);
        spec.width = View.MeasureSpec.makeMeasureSpec(resolvedWidth, View.MeasureSpec.EXACTLY);
    }
}
 
源代码5 项目: letv   文件: ViewCompat.java
public int resolveSizeAndState(int size, int measureSpec, int childMeasuredState) {
    return View.resolveSize(size, measureSpec);
}
 
源代码6 项目: FanXin-based-HuanXin   文件: AspectRatioMeasure.java
/**
 * Updates the given measure spec with respect to the aspect ratio.
 *
 * <p>Note: Measure spec is not changed if the aspect ratio is not greater than zero.
 *
 * <p>Measure spec of the layout dimension (width or height) specified as "0dp" is updated
 * to match the measure spec of the other dimension adjusted by the aspect ratio. Exactly one
 * layout dimension should be specified as "0dp".
 *
 * <p>Padding is taken into account so that the aspect ratio refers to the content without
 * padding: {@code aspectRatio == (viewWidth - widthPadding) / (viewHeight - heightPadding)}
 *
 * <p>Updated measure spec respects the parent's constraints. I.e. measure spec is not changed
 * if the parent has specified mode {@code EXACTLY}, and it doesn't exceed measure size if parent
 * has specified mode {@code AT_MOST}.
 *
 * @param spec in/out measure spec to be updated
 * @param aspectRatio desired aspect ratio
 * @param layoutParams view's layout params
 * @param widthPadding view's left + right padding
 * @param heightPadding view's top + bottom padding
 */
public static void updateMeasureSpec(
    Spec spec,
    float aspectRatio,
    ViewGroup.LayoutParams layoutParams,
    int widthPadding,
    int heightPadding) {
  if (aspectRatio <= 0) {
    return;
  }
  if (shouldAdjust(layoutParams.height)) {
    int widthSpecSize = View.MeasureSpec.getSize(spec.width);
    int desiredHeight = (int) ((widthSpecSize - widthPadding) / aspectRatio + heightPadding);
    int resolvedHeight = View.resolveSize(desiredHeight, spec.height);
    spec.height = View.MeasureSpec.makeMeasureSpec(resolvedHeight, View.MeasureSpec.EXACTLY);
  } else if (shouldAdjust(layoutParams.width)) {
    int heightSpecSize = View.MeasureSpec.getSize(spec.height);
    int desiredWidth = (int) ((heightSpecSize - heightPadding) * aspectRatio + widthPadding);
    int resolvedWidth = View.resolveSize(desiredWidth, spec.width);
    spec.width = View.MeasureSpec.makeMeasureSpec(resolvedWidth, View.MeasureSpec.EXACTLY);
  }
}
 
源代码7 项目: fresco   文件: AspectRatioMeasure.java
/**
 * Updates the given measure spec with respect to the aspect ratio.
 *
 * <p>Note: Measure spec is not changed if the aspect ratio is not greater than zero or if
 * layoutParams is null.
 *
 * <p>Measure spec of the layout dimension (width or height) specified as "0dp" is updated to
 * match the measure spec of the other dimension adjusted by the aspect ratio. Exactly one layout
 * dimension should be specified as "0dp".
 *
 * <p>Padding is taken into account so that the aspect ratio refers to the content without
 * padding: {@code aspectRatio == (viewWidth - widthPadding) / (viewHeight - heightPadding)}
 *
 * <p>Updated measure spec respects the parent's constraints. I.e. measure spec is not changed if
 * the parent has specified mode {@code EXACTLY}, and it doesn't exceed measure size if parent has
 * specified mode {@code AT_MOST}.
 *
 * @param spec in/out measure spec to be updated
 * @param aspectRatio desired aspect ratio
 * @param layoutParams view's layout params
 * @param widthPadding view's left + right padding
 * @param heightPadding view's top + bottom padding
 */
public static void updateMeasureSpec(
    Spec spec,
    float aspectRatio,
    @Nullable ViewGroup.LayoutParams layoutParams,
    int widthPadding,
    int heightPadding) {
  if (aspectRatio <= 0 || layoutParams == null) {
    return;
  }
  if (shouldAdjust(layoutParams.height)) {
    int widthSpecSize = View.MeasureSpec.getSize(spec.width);
    int desiredHeight = (int) ((widthSpecSize - widthPadding) / aspectRatio + heightPadding);
    int resolvedHeight = View.resolveSize(desiredHeight, spec.height);
    spec.height = View.MeasureSpec.makeMeasureSpec(resolvedHeight, View.MeasureSpec.EXACTLY);
  } else if (shouldAdjust(layoutParams.width)) {
    int heightSpecSize = View.MeasureSpec.getSize(spec.height);
    int desiredWidth = (int) ((heightSpecSize - heightPadding) * aspectRatio + widthPadding);
    int resolvedWidth = View.resolveSize(desiredWidth, spec.width);
    spec.width = View.MeasureSpec.makeMeasureSpec(resolvedWidth, View.MeasureSpec.EXACTLY);
  }
}
 
源代码8 项目: adt-leanback-support   文件: ViewCompat.java
public int resolveSizeAndState(int size, int measureSpec, int childMeasuredState) {
    return View.resolveSize(size, measureSpec);
}
 
源代码9 项目: android-recipes-app   文件: ViewCompat.java
public int resolveSizeAndState(int size, int measureSpec, int childMeasuredState) {
    return View.resolveSize(size, measureSpec);
}
 
源代码10 项目: V.FlyoutTest   文件: ViewCompat.java
public int resolveSizeAndState(int size, int measureSpec, int childMeasuredState) {
    return View.resolveSize(size, measureSpec);
}
 
源代码11 项目: guideshow   文件: ViewCompat.java
public int resolveSizeAndState(int size, int measureSpec, int childMeasuredState) {
    return View.resolveSize(size, measureSpec);
}
 
 方法所在类
 同类方法