public void restoreOriginalParams() { int i = 0; for (int N = this.mHost.getChildCount(); i < N; ++i) { View view = this.mHost.getChildAt(i); LayoutParams params = view.getLayoutParams(); if (Log.isLoggable("PercentLayout", 3)) { Log.d("PercentLayout", "should restore " + view + " " + params); } if (params instanceof PercentLayoutHelper.PercentLayoutParams) { PercentLayoutHelper.PercentLayoutInfo info = ((PercentLayoutHelper.PercentLayoutParams) params).getPercentLayoutInfo(); if (Log.isLoggable("PercentLayout", 3)) { Log.d("PercentLayout", "using " + info); } if (info != null) { if (params instanceof MarginLayoutParams) { info.restoreMarginLayoutParams((MarginLayoutParams) params); } else { info.restoreLayoutParams(params); } } } } }
public void adjustChildren(int widthMeasureSpec, int heightMeasureSpec) { if (Log.isLoggable("PercentLayout", 3)) { Log.d( "PercentLayout", "adjustChildren: " + this.mHost + " widthMeasureSpec: " + MeasureSpec.toString(widthMeasureSpec) + " heightMeasureSpec: " + MeasureSpec.toString(heightMeasureSpec)); } int widthHint = MeasureSpec.getSize(widthMeasureSpec); int heightHint = MeasureSpec.getSize(heightMeasureSpec); int i = 0; for (int N = this.mHost.getChildCount(); i < N; ++i) { View view = this.mHost.getChildAt(i); LayoutParams params = view.getLayoutParams(); if (Log.isLoggable("PercentLayout", 3)) { Log.d("PercentLayout", "should adjust " + view + " " + params); } if (params instanceof PercentLayoutHelper.PercentLayoutParams) { PercentLayoutHelper.PercentLayoutInfo info = ((PercentLayoutHelper.PercentLayoutParams) params).getPercentLayoutInfo(); if (Log.isLoggable("PercentLayout", 3)) { Log.d("PercentLayout", "using " + info); } if (info != null) { if (params instanceof MarginLayoutParams) { info.fillMarginLayoutParams((MarginLayoutParams) params, widthHint, heightHint); } else { info.fillLayoutParams(params, widthHint, heightHint); } } } } }
public static PercentLayoutHelper.PercentLayoutInfo getPercentLayoutInfo( Context context, AttributeSet attrs) { PercentLayoutHelper.PercentLayoutInfo info = null; TypedArray array = context.obtainStyledAttributes(attrs, styleable.PercentLayout_Layout); float value = array.getFraction(styleable.PercentLayout_Layout_layout_widthPercent, 1, 1, -1.0F); if (value != -1.0F) { if (Log.isLoggable("PercentLayout", 2)) { Log.v("PercentLayout", "percent width: " + value); } info = info != null ? info : new PercentLayoutHelper.PercentLayoutInfo(); info.widthPercent = value; } value = array.getFraction(styleable.PercentLayout_Layout_layout_heightPercent, 1, 1, -1.0F); if (value != -1.0F) { if (Log.isLoggable("PercentLayout", 2)) { Log.v("PercentLayout", "percent height: " + value); } info = info != null ? info : new PercentLayoutHelper.PercentLayoutInfo(); info.heightPercent = value; } value = array.getFraction(styleable.PercentLayout_Layout_layout_marginPercent, 1, 1, -1.0F); if (value != -1.0F) { if (Log.isLoggable("PercentLayout", 2)) { Log.v("PercentLayout", "percent margin: " + value); } info = info != null ? info : new PercentLayoutHelper.PercentLayoutInfo(); info.leftMarginPercent = value; info.topMarginPercent = value; info.rightMarginPercent = value; info.bottomMarginPercent = value; } value = array.getFraction(styleable.PercentLayout_Layout_layout_marginLeftPercent, 1, 1, -1.0F); if (value != -1.0F) { if (Log.isLoggable("PercentLayout", 2)) { Log.v("PercentLayout", "percent left margin: " + value); } info = info != null ? info : new PercentLayoutHelper.PercentLayoutInfo(); info.leftMarginPercent = value; } value = array.getFraction(styleable.PercentLayout_Layout_layout_marginTopPercent, 1, 1, -1.0F); if (value != -1.0F) { if (Log.isLoggable("PercentLayout", 2)) { Log.v("PercentLayout", "percent top margin: " + value); } info = info != null ? info : new PercentLayoutHelper.PercentLayoutInfo(); info.topMarginPercent = value; } value = array.getFraction(styleable.PercentLayout_Layout_layout_marginRightPercent, 1, 1, -1.0F); if (value != -1.0F) { if (Log.isLoggable("PercentLayout", 2)) { Log.v("PercentLayout", "percent right margin: " + value); } info = info != null ? info : new PercentLayoutHelper.PercentLayoutInfo(); info.rightMarginPercent = value; } value = array.getFraction(styleable.PercentLayout_Layout_layout_marginBottomPercent, 1, 1, -1.0F); if (value != -1.0F) { if (Log.isLoggable("PercentLayout", 2)) { Log.v("PercentLayout", "percent bottom margin: " + value); } info = info != null ? info : new PercentLayoutHelper.PercentLayoutInfo(); info.bottomMarginPercent = value; } value = array.getFraction(styleable.PercentLayout_Layout_layout_marginStartPercent, 1, 1, -1.0F); if (value != -1.0F) { if (Log.isLoggable("PercentLayout", 2)) { Log.v("PercentLayout", "percent start margin: " + value); } info = info != null ? info : new PercentLayoutHelper.PercentLayoutInfo(); info.startMarginPercent = value; } value = array.getFraction(styleable.PercentLayout_Layout_layout_marginEndPercent, 1, 1, -1.0F); if (value != -1.0F) { if (Log.isLoggable("PercentLayout", 2)) { Log.v("PercentLayout", "percent end margin: " + value); } info = info != null ? info : new PercentLayoutHelper.PercentLayoutInfo(); info.endMarginPercent = value; } array.recycle(); if (Log.isLoggable("PercentLayout", 3)) { Log.d("PercentLayout", "constructed: " + info); } return info; }