Java Code Examples for android.view.View.resolveSize()

The following are Jave code examples for showing how to use resolveSize() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: AnimationWrapLayout   File: AnimationWrapLayout.java   View Source Code Vote up 7 votes
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int width = View.resolveSize(getSuggestedMinimumWidth(), widthMeasureSpec);
    int height = View.resolveSize(getSuggestedMinimumHeight(), heightMeasureSpec);

    int childWidthSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.UNSPECIFIED);
    int childHeightSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED);

    int count = this.getChildCount();
    for (int i = 0; i < count; i++) {
        getChildAt(i).measure(childWidthSpec, childHeightSpec);
    }

    height = mChildrenMeasure.measureByTotalWidth(width).getTotalHeight();
    if (mChildrenMeasure.hasPreLayoutView() && getMeasuredHeight() > height) {
        height = getMeasuredHeight();
    }
    this.setMeasuredDimension(width, height);
}
 
Example 2
Project: GitHub   File: AspectRatioMeasure.java   View Source Code Vote up 5 votes
/**
 * 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);
  }
}
 
Example 3
Project: CSipSimple   File: Utility4.java   View Source Code Vote up 5 votes
@Override
public int resolveSizeAndState(int size, int measureSpec, int state) {
    return View.resolveSize(size, measureSpec);
}
 
Example 4
Project: JD-Test   File: PercentAspectRatioMeasure.java   View Source Code Vote up 5 votes
/**
 * 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);
    }
}
 
Example 5
Project: JD-Test   File: BannerAspectRatioMeasure.java   View Source Code Vote up 5 votes
/**
 * 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);
    }
}
 
Example 6
Project: letv   File: ViewCompat.java   View Source Code Vote up 5 votes
public int resolveSizeAndState(int size, int measureSpec, int childMeasuredState) {
    return View.resolveSize(size, measureSpec);
}
 
Example 7
Project: boohee_v5.6   File: ViewCompat.java   View Source Code Vote up 5 votes
public int resolveSizeAndState(int size, int measureSpec, int childMeasuredState) {
    return View.resolveSize(size, measureSpec);
}