Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复使用java代码无法设置控件高度、宽度、边距以及文本大小的问题 #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
}

Expand All @@ -59,7 +63,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
if (!isInEditMode())
{
mHelper.adjustChildren();
mHelper.adjustChildren(mContext,mAttrs);
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -52,14 +54,16 @@ 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);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
if (!isInEditMode())
mHelper.adjustChildren();
mHelper.adjustChildren(mContext,mAttrs);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ private void initAutoLayoutConfig(ViewGroup host)
}


public void adjustChildren()
public void adjustChildren(Context context,
AttributeSet attrs)
{
AutoLayoutConifg.getInstance().checkParams();

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down