我想动态地在相对布局上添加textView,我想在画布上显示它。我试过以下代码。请帮我弄清楚是什么问题!提前谢谢。
公共类MainActivity2扩展了Activity {
Paint p= new Paint();
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
View myView= new Panel(this);
setContentView(myView);
p.setColor(Color.BLUE);
}
class Panel extends View
{
RelativeLayout rl= new RelativeLayout(getApplicationContext());
TextView tv = new TextView(getApplicationContext());
public Panel(Context context) {
super(context);
tv.setText("Helllllloo");
rl.addView(tv);
}
@Override
public void onDraw(Canvas canvas)
{
rl.draw(canvas);
canvas.drawText("helllo canvas!1!!!!!!!", 0, 100, p);
}
}
}
答案 0 :(得分:0)
我通过向相对布局添加单独的视图并将内容视图设置为相对布局来解决它!