diff --git a/autolayout/src/main/java/com/zhy/autolayout/AutoFrameLayout.java b/autolayout/src/main/java/com/zhy/autolayout/AutoFrameLayout.java index 595d933..fb50226 100644 --- a/autolayout/src/main/java/com/zhy/autolayout/AutoFrameLayout.java +++ b/autolayout/src/main/java/com/zhy/autolayout/AutoFrameLayout.java @@ -27,6 +27,8 @@ public class AutoFrameLayout extends FrameLayout { private final AutoLayoutHelper mHelper = new AutoLayoutHelper(this); + private Context mContext; + private AttributeSet mAttrs; public AutoFrameLayout(Context context) { @@ -51,6 +53,8 @@ public AutoFrameLayout(Context context, AttributeSet attrs, int defStyleAttr, in @Override public LayoutParams generateLayoutParams(AttributeSet attrs) { + this.mContext = getContext(); + this.mAttrs = attrs; return new LayoutParams(getContext(), attrs); } @@ -59,7 +63,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (!isInEditMode()) { - mHelper.adjustChildren(); + mHelper.adjustChildren(mContext,mAttrs); } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } diff --git a/autolayout/src/main/java/com/zhy/autolayout/AutoLinearLayout.java b/autolayout/src/main/java/com/zhy/autolayout/AutoLinearLayout.java index f0f93d6..8a11d0c 100644 --- a/autolayout/src/main/java/com/zhy/autolayout/AutoLinearLayout.java +++ b/autolayout/src/main/java/com/zhy/autolayout/AutoLinearLayout.java @@ -16,6 +16,8 @@ public class AutoLinearLayout extends LinearLayout { private AutoLayoutHelper mHelper = new AutoLayoutHelper(this); + private Context mContext; + private AttributeSet mAttrs; public AutoLinearLayout(Context context) { super(context); @@ -39,7 +41,7 @@ public AutoLinearLayout(Context context, AttributeSet attrs, int defStyleAttr, i protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (!isInEditMode()) - mHelper.adjustChildren(); + mHelper.adjustChildren(mContext,mAttrs); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } @@ -54,6 +56,8 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) @Override public LayoutParams generateLayoutParams(AttributeSet attrs) { + this.mContext = getContext(); + this.mAttrs = attrs; return new AutoLinearLayout.LayoutParams(getContext(), attrs); } diff --git a/autolayout/src/main/java/com/zhy/autolayout/AutoRelativeLayout.java b/autolayout/src/main/java/com/zhy/autolayout/AutoRelativeLayout.java index c107e57..b84828b 100644 --- a/autolayout/src/main/java/com/zhy/autolayout/AutoRelativeLayout.java +++ b/autolayout/src/main/java/com/zhy/autolayout/AutoRelativeLayout.java @@ -28,6 +28,8 @@ public class AutoRelativeLayout extends RelativeLayout { private final AutoLayoutHelper mHelper = new AutoLayoutHelper(this); + private Context mContext; + private AttributeSet mAttrs; public AutoRelativeLayout(Context context) { @@ -52,6 +54,8 @@ public AutoRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr, @Override public LayoutParams generateLayoutParams(AttributeSet attrs) { + this.mContext = getContext(); + this.mAttrs = attrs; return new LayoutParams(getContext(), attrs); } @@ -59,7 +63,7 @@ public LayoutParams generateLayoutParams(AttributeSet attrs) protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (!isInEditMode()) - mHelper.adjustChildren(); + mHelper.adjustChildren(mContext,mAttrs); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } diff --git a/autolayout/src/main/java/com/zhy/autolayout/utils/AutoLayoutHelper.java b/autolayout/src/main/java/com/zhy/autolayout/utils/AutoLayoutHelper.java index 9ac666e..7683cbd 100644 --- a/autolayout/src/main/java/com/zhy/autolayout/utils/AutoLayoutHelper.java +++ b/autolayout/src/main/java/com/zhy/autolayout/utils/AutoLayoutHelper.java @@ -112,7 +112,8 @@ private void initAutoLayoutConfig(ViewGroup host) } - public void adjustChildren() + public void adjustChildren(Context context, + AttributeSet attrs) { AutoLayoutConifg.getInstance().checkParams(); @@ -123,8 +124,8 @@ public void adjustChildren() if (params instanceof AutoLayoutParams) { - AutoLayoutInfo info = - ((AutoLayoutParams) params).getAutoLayoutInfo(); +// AutoLayoutInfo info =((AutoLayoutParams) params).getAutoLayoutInfo(); + AutoLayoutInfo info =getAutoLayoutInfo(context,attrs); if (info != null) { info.fillAttrs(view); diff --git a/autolayout/src/main/java/com/zhy/autolayout/widget/MetroLayout.java b/autolayout/src/main/java/com/zhy/autolayout/widget/MetroLayout.java index 44c732e..f95f07e 100644 --- a/autolayout/src/main/java/com/zhy/autolayout/widget/MetroLayout.java +++ b/autolayout/src/main/java/com/zhy/autolayout/widget/MetroLayout.java @@ -25,6 +25,8 @@ public class MetroLayout extends ViewGroup { private final AutoLayoutHelper mHelper = new AutoLayoutHelper(this); + private Context mContext; + private AttributeSet mAttrs; private static class MetroBlock { @@ -54,7 +56,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) randomColor(); if (!isInEditMode()) - mHelper.adjustChildren(); + mHelper.adjustChildren(mContext,mAttrs); measureChildren(widthMeasureSpec, heightMeasureSpec); super.onMeasure(widthMeasureSpec, heightMeasureSpec); @@ -186,6 +188,8 @@ private MetroBlock findAvailablePos(View view) @Override public MetroLayout.LayoutParams generateLayoutParams(AttributeSet attrs) { + this.mContext = getContext(); + this.mAttrs = attrs; return new LayoutParams(getContext(), attrs); }