編輯:中級開發
public class FitCenterFrameLayout extends VIEwGroup {
public FitCenterFrameLayout(Context context) {
super(context);
}
public FitCenterFrameLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { //修改尺寸
final int width = resolveSize(getSuggestedMinimumWidth(), widthMeasureSpec);
final int height = resolveSize(getSuggestedMinimumHeight(), heightMeasureSpec);
setMeasuredDimension(width, height);
int childWidthSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.UNSPECIFIED);
int childHeightSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED);
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
getChildAt(i).measure(childWidthSpec, childHeightSpec);
}
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
final int childCount = getChildCount();
final int parentLeft = getPaddingLeft();
final int parentTop = getPaddingTop();
final int parentRight = r - l - getPaddingRight();
final int parentBottom = b - t - getPaddingBottom();
final int parentWidth = parentRight - parentLeft;
final int parentHeight = parentBottom - parentTop;
int unpaddedWidth, unpaddedHeight, parentUnpaddedWidth, parentUnpaddedHeight;
int childPaddingLeft, childPaddingTop, childPaddingRight, childPaddingBottom;
for (int i = 0; i < childCount; i++) {
final VIEw child = getChildAt(i);
if (child.getVisibility() == GONE) {
continue;
}
childPaddingLeft = child.getPaddingLeft();
childPaddingTop = child.getPaddingTop();
childPaddingRight = child.getPaddingRight();
childPaddingBottom = child.getPaddingBottom();
unpaddedWidth = child.getMeasuredWidth() - childPaddingLeft - childPaddingRight;
unpaddedHeight = child.getMeasuredHeight() - childPaddingTop - childPaddingBottom;
parentUnpaddedWidth = parentWidth - childPaddingLeft - childPaddingRight;
parentUnpaddedHeight = parentHeight - childPaddingTop - childPaddingBottom;
if (parentUnpaddedWidth * unpaddedHeight > parentUnpaddedHeight * unpaddedWidth) {
final int scaledChildWidth = unpaddedWidth * parentUnpaddedHeight
/ unpaddedHeight + childPaddingLeft + childPaddingRight;
child.layout(
parentLeft + (parentWidth - scaledChildWidth) / 2,
parentTop,
parentRight - (parentWidth - scaledChildWidth) / 2,
parentBottom);
} else {
final int scaledChildHeight = unpaddedHeight * parentUnpaddedWidth
/ unpaddedWidth + childPaddingTop + childPaddingBottom;
child.layout(
parentLeft,
parentTop + (parentHeight - scaledChildHeight) / 2,
parentRight,
parentTop + (parentHeight + scaledChildHeight) / 2);
}
}
}
}
簡介: Java™ 語言是 Android 開發人員所選的工具。android 運行時使用自己的虛擬機 Dalvik,這並不是多數程序開發人員使用
Android ANR這個錯誤大家並不陌生,但是從Android 2.2開始出錯的ANR信息會自動上傳給Google進行系統分析改進,當然了你的應用ANR錯誤其實保存在
簡介: 本文是共兩部分的系列文章 “android 和 iPhone 浏覽器之戰” 的第 2 部分,主要關注為 iPhone 和 Android 開發基於浏覽
這幾天搞了搞AIDL,終於弄明白了在AIDL中讓Service調用Activity的方法代碼:首先建立一個ICallback.aidl文件,作為Activity中的回調