ScaleFrameLayoutpublic class ScaleFrameLayout extends android.widget.FrameLayout Subclass of FrameLayout that support scale layout area size for children. |
Fields Summary |
---|
private static final int | DEFAULT_CHILD_GRAVITY | private float | mLayoutScaleX | private float | mLayoutScaleY |
Methods Summary |
---|
private static int | getScaledMeasureSpec(int measureSpec, float scale)
return scale == 1f ? measureSpec : MeasureSpec.makeMeasureSpec(
(int) (MeasureSpec.getSize(measureSpec) / scale + 0.5f),
MeasureSpec.getMode(measureSpec));
| protected void | onLayout(boolean changed, int left, int top, int right, int bottom)
final int count = getChildCount();
final int parentLeft, parentRight;
final int layoutDirection = getLayoutDirection();
final float pivotX = (layoutDirection == View.LAYOUT_DIRECTION_RTL) ?
getWidth() - getPivotX() :
getPivotX();
if (mLayoutScaleX != 1f) {
parentLeft = getPaddingLeft() + (int)(pivotX - pivotX / mLayoutScaleX + 0.5f);
parentRight = (int)(pivotX + (right - left - pivotX) / mLayoutScaleX + 0.5f)
- getPaddingRight();
} else {
parentLeft = getPaddingLeft();
parentRight = right - left - getPaddingRight();
}
final int parentTop, parentBottom;
final float pivotY = getPivotY();
if (mLayoutScaleY != 1f) {
parentTop = getPaddingTop() + (int)(pivotY - pivotY / mLayoutScaleY + 0.5f);
parentBottom = (int)(pivotY + (bottom - top - pivotY) / mLayoutScaleY + 0.5f)
- getPaddingBottom();
} else {
parentTop = getPaddingTop();
parentBottom = bottom - top - getPaddingBottom();
}
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() != GONE) {
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
final int width = child.getMeasuredWidth();
final int height = child.getMeasuredHeight();
int childLeft;
int childTop;
int gravity = lp.gravity;
if (gravity == -1) {
gravity = DEFAULT_CHILD_GRAVITY;
}
final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection);
final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
case Gravity.CENTER_HORIZONTAL:
childLeft = parentLeft + (parentRight - parentLeft - width) / 2 +
lp.leftMargin - lp.rightMargin;
break;
case Gravity.RIGHT:
childLeft = parentRight - width - lp.rightMargin;
break;
case Gravity.LEFT:
default:
childLeft = parentLeft + lp.leftMargin;
}
switch (verticalGravity) {
case Gravity.TOP:
childTop = parentTop + lp.topMargin;
break;
case Gravity.CENTER_VERTICAL:
childTop = parentTop + (parentBottom - parentTop - height) / 2 +
lp.topMargin - lp.bottomMargin;
break;
case Gravity.BOTTOM:
childTop = parentBottom - height - lp.bottomMargin;
break;
default:
childTop = parentTop + lp.topMargin;
}
child.layout(childLeft, childTop, childLeft + width, childTop + height);
// synchronize child pivot to be same as ScaleFrameLayout's pivot
child.setPivotX(pivotX - childLeft);
child.setPivotY(pivotY - childTop);
}
}
| protected void | onMeasure(int widthMeasureSpec, int heightMeasureSpec)
if (mLayoutScaleX != 1f || mLayoutScaleY != 1f) {
final int scaledWidthMeasureSpec =
getScaledMeasureSpec(widthMeasureSpec, mLayoutScaleX);
final int scaledHeightMeasureSpec =
getScaledMeasureSpec(heightMeasureSpec, mLayoutScaleY);
super.onMeasure(scaledWidthMeasureSpec, scaledHeightMeasureSpec);
setMeasuredDimension((int)(getMeasuredWidth() * mLayoutScaleX + 0.5f),
(int)(getMeasuredHeight() * mLayoutScaleY + 0.5f));
} else {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
| public void | setForeground(android.graphics.drawable.Drawable d)setForeground() is not supported, throws UnsupportedOperationException() when called.
throw new UnsupportedOperationException();
| public void | setLayoutScaleX(float scaleX)
if (scaleX != mLayoutScaleX) {
mLayoutScaleX = scaleX;
requestLayout();
}
| public void | setLayoutScaleY(float scaleY)
if (scaleY != mLayoutScaleY) {
mLayoutScaleY = scaleY;
requestLayout();
}
|
|