@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int width = MeasureSpec.getSize(widthMeasureSpec); int widthMode = MeasureSpec.getMode(widthMeasureSpec); int height = MeasureSpec.getSize(heightMeasureSpec); int heightMode = MeasureSpec.getMode(heightMeasureSpec); if (widthMode == MeasureSpec.EXACTLY || widthMode == MeasureSpec.AT_MOST) { height = calculate(width, aspect, VERTICAL); } else if (heightMode == MeasureSpec.EXACTLY || heightMode == MeasureSpec.AT_MOST) { width = calculate(height, aspect, HORIZONTAL); } else if (width != 0) { height = calculate(width, aspect, VERTICAL); } else if (height != 0) { width = calculate(height, aspect, HORIZONTAL); } else { Log.e(AspectImageView.class.getSimpleName(), "Either width or height should have exact value"); } int specWidth = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY); int specHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); super.onMeasure(specWidth, specHeight); }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { Drawable drawable = getDrawable(); if (drawable != null) { int width = MeasureSpec.getSize(widthMeasureSpec); int diw = drawable.getIntrinsicWidth(); if (diw > 0) { int height = width * drawable.getIntrinsicHeight() / diw; setMeasuredDimension(width, height); return; } } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if (mIsSquare) { int measuredWidth = MeasureSpec.getSize(widthMeasureSpec); int size = measuredWidth == 0 ? MeasureSpec.getSize(heightMeasureSpec) : measuredWidth; setMeasuredDimension(size, size); } }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { final int widthMode = MeasureSpec.getMode(widthMeasureSpec); if (widthMode == MeasureSpec.AT_MOST || widthMode == MeasureSpec.UNSPECIFIED) { final int widthSize = MeasureSpec.getSize(widthMeasureSpec); final int maxWidth = getMaxWidth(); if (maxWidth != Integer.MAX_VALUE && (maxWidth < widthSize || widthMode == MeasureSpec.UNSPECIFIED)) { widthMeasureSpec = MeasureSpec.makeMeasureSpec(maxWidth, MeasureSpec.AT_MOST); } } final int heightMode = MeasureSpec.getMode(heightMeasureSpec); if (heightMode == MeasureSpec.AT_MOST || heightMode == MeasureSpec.UNSPECIFIED) { final int heightSize = MeasureSpec.getSize(heightMeasureSpec); final int maxHeight = getMaxHeight(); if (maxHeight != Integer.MAX_VALUE && (maxHeight < heightSize || heightMode == MeasureSpec.UNSPECIFIED)) { heightMeasureSpec = MeasureSpec.makeMeasureSpec(maxHeight, MeasureSpec.AT_MOST); } } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } }
/** * Adjust Dimensions to create a square image view that matches the parents width. */ @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); int width = getMeasuredWidth(); setMeasuredDimension(width, width); } }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); int size; if (mSize <= 0) size = (int) Math.ceil( (mProgress.getCenterRadius() + mProgress.getStrokeWidth() + mPaddingEdge) * 2); else size = (int) Math.ceil(mSize); if (mShowShadowsCircle && !elevationSupported()) { size += Math.round(mElevation * 2); } setMeasuredDimension(resolveSize(size, widthMeasureSpec), resolveSize(size, heightMeasureSpec)); }