MyViewボタンを押してサイズを変更したい。
の初期サイズは 400 * 400で、ボタンをMyView押すたびに100 が追加されます。ビューのサイズは変更されるはずですが、400 * 400 のままです。および行 b) の両方のサイズと変更サイズ。これがどのように起こるかわかりません。のサイズを動的に変更したいだけの場合、どうすればよいですか?b1wb2ClickListenerb2MyViewMyView
関連コード:
public class MyView extends RelativeLayout {
Button b1;
Button b2;
Context sContext;
public static int i = 0;
private int w = 400;
private int h = 400;
private int w2 = 100;
private int h2 = 100;
public MyView(Context context) {
    super(context);
    sContext = context;
    init();
}
public MyView(Context context, AttributeSet attrs) {
    super(context, attrs);
    sContext = context;
    init();
}
private void init() {
    b1 = new Button(sContext);
    b2 = new Button(sContext);
    addView(b1);
    addView(b2);
    b1.setBackgroundColor(Color.YELLOW);
    b2.setX(500);
    b1.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if (MyView.this.getLayoutParams() == null) {
                MyView.this.setLayoutParams(new FrameLayout.LayoutParams(w, h));
            } else {
                MyView.this.getLayoutParams().width = w;
                MyView.this.getLayoutParams().height = h;
            }
                MyView.this.setBackgroundColor(Color.GREEN);
            //b2.setWidth(w2);          line a
            //b2.setHeight(h2);         line b
            //MyView.this.invalidate();
            w += 100;
            w2 += 20;
        }
    });
}
@Override
protected void onDraw(Canvas canvas) {
    //super.onDraw(canvas);
    test();
}
private void test() {
    b2.setBackgroundColor(Color.BLUE);
    b2.setX(200.0f);
    Toast.makeText(sContext, ""+i, Toast.LENGTH_SHORT).show();
    ++i;
}
}