开发者

issue with CustomView drawing in my application

开发者 https://www.devze.com 2023-04-09 23:09 出处:网络
What is wrong in my code here.why it is not drawing my customview on screen. class CustActivty extends Activty{

What is wrong in my code here.why it is not drawing my customview on screen.

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 anyb开发者_开发知识库ody having idea.Plz help.


You should specify the LayoutParams that your view will use to be added to the RelativeLayout

So instead of just rl.addView(view)

RelativeLayout.LayoutParams params = //initialise them as you want
rl.addView(view, params);
0

精彩评论

暂无评论...
验证码 换一张
取 消