1

我想在相对布局上动态添加一个 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);

    }



}

}

4

1 回答 1

0

我通过向相对布局添加单独的视图并将 contentview 设置为该相对布局来解决它!

于 2013-08-10T10:15:16.940 回答