【发布时间】:2012-01-09 01:17:31
【问题描述】:
我正在尝试将视图添加到自定义视图组。 ViewGroup 被绘制,但添加到其中的视图不可见。 LineView(扩展视图)的 onDraw() 方法不会被调用。我做错了什么?
public class TestActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ShapeView shapeView = new ShapeView(this);
shapeView.setBackgroundColor(Color.RED);
drawContainer = (RelativeLayout)findViewById(R.id.draw_container);
drawContainer.addView(shapeView);
}
}
public class ShapeView extends ViewGroup {
private LineView mLineView;
public ShapeView (Context context) {
super(context);
RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(200, 200);
this.setLayoutParams(p);
mLineView = new LineView(context);
this.addView(mLineView);
}
}
【问题讨论】:
标签: android