我的代碼在這裏有什麼問題,爲什麼它不是在屏幕上繪製我的自定義視圖。問題與我的應用程序中的自定義繪圖
class CustActivty extends Activty{
private ShapeDrawable mDrawable;;
Path path;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.imagelayout);
CustomView view=new CustomView(getApplicationContext());
RelativeLayout rl=(RelativeLayout)findViewById(R.id.relativeLayout1);
rl.addView(view);
}
class CustomView extends View{
CustomView(Context context){
super(context); path = new Path(); RectF rec = new RectF(10,10,400,400);
path.addArc(rec,90,180);
mDrawable = new ShapeDrawable(new PathShape(path,400,400));
mDrawable.setBounds(10, 10, 400,400);
mDrawable.getPaint().setColor(0xff74AC23);
}
protected void onDraw(Canvas canvas){
mDrawable.draw(canvas);
}
}
}
Plz任何人都有idea.Plz幫助。
嘗試'的setContentView(圖)'忘了'rl'的..告訴我如果它畫 –
是的,它正在繪製沒有relativelayout.然後相對佈局的問題是什麼? –
你必須'rl.addView(view,params);''params'應該被定義爲'RelativeLayout.LayoutParams' –