我的应用程序中的 CustomView 绘图问题
我的代码有什么问题。为什么它没有在屏幕上绘制我的自定义视图。
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){
超级(上下文); 路径=新路径(); 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);
}
}
}
请任何有想法的人。请帮忙。
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 anybody having idea.Plz help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该指定
view
将使用的LayoutParams
添加到RelativeLayout
中,而不只是
rl.addView(view)
You should specify the
LayoutParams
that yourview
will use to be added to theRelativeLayout
So instead of just
rl.addView(view)