【发布时间】:2015-01-14 08:57:43
【问题描述】:
我尝试在扩展的 LinearLayout 中调整组件的大小。 在方法 onLayout() 中。
public ExtLinearLayout(Context context, AttributeSet attrs, int defStyle) {
super(context,attrs,0);
init(attrs);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
Log.d(TAG,
"OnLayout1: Left: " + l + "Right: " + r + "Top: " + t + "Bottom: " + b + " children" + this.getChildCount() + " changed" + changed + " getHeight "
+ this.getMeasuredHeight() + " getWidth " + this.getMeasuredWidth());
Child c = (SeedBar) this.getChildAt(0);
c.setLayoutParams(new LinearLayout.LayoutParams(20,this.getMeasuredHeight()-23));
super.onLayout(changed, l, t, r, b);
}
private void init(AttributeSet attrs) {
this.setOrientation(LinearLayout.VERTICAL);
this.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
this.configureChild();
this.invalidate();
}
private void configureChild() {
Child c = new SeedBar(getContext());
c.setLayoutParams(new LayoutParams(20, 100));
this.addView(c, 0);
}
所以我会在 onLayout() 方法中添加一个 Child 并设置 Size,但什么都不会发生。 Child 是从 View 扩展而来的
【问题讨论】:
-
你想通过改变布局过程中的布局来达到什么目的?
-
如果布局中有多个子级,或者 parentLayout 会改变大小,我会将 Child 调整为运行时大小。你明白吗?
标签: android android-linearlayout android-view