1
我想在相對佈局上動態添加textView,並且我想在畫布上顯示它。我已經嘗試了下面的代碼。請幫我找出有什麼問題!提前致謝。TextView未出現在畫布上
公共類MainActivity2擴展活動 {
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);
}
}
}
你好帆布顯示在這裏。但不是hellollo ..爲什麼這樣呢? – AshMv