Java 使用“更改变量”(动画)在画布中绘制圆

Java 使用“更改变量”(动画)在画布中绘制圆,java,android,variables,canvas,draw,Java,Android,Variables,Canvas,Draw,你好 我是初学者。 我想用这段代码画一个圆球,但它不起作用。它不会向我发送错误,但它什么也没画: float width = this.getWidth(), height = this.getHeight();//Ns permet de savoir la resolution // float posXj=(width/2), posYj=(height-50);//position de depart du joueur // boolean dGauche=false,dDroite=

你好

我是初学者。 我想用这段代码画一个圆球,但它不起作用。它不会向我发送错误,但它什么也没画:

float width = this.getWidth(), height = this.getHeight();//Ns permet de savoir la resolution
//
float posXj=(width/2), posYj=(height-50);//position de depart du joueur
//
boolean dGauche=false,dDroite=false;//d=deplacement

//------------------Dessine Le Joueur------------------
protected void onDraw(Canvas canvas) {

//canvas.;
Paint pPrincipal = new Paint();
pPrincipal.setAntiAlias(true);

pPrincipal.setColor(Color.parseColor("#778899"));
canvas.drawCircle(this.posXj,this.posYj,25,pPrincipal );

}
//--------------FIN:Dessine Le Joueur------------------
我知道问题来自以下方面:

float width = this.getWidth(), height = this.getHeight();
它不返回尖叫的宽度和高度。 但是我需要这样写这个变量,因为在我想用我的圆做一个基本的动画之后

谢谢你们的帮助。 敬礼


PS:对不起我的英语,我是法国人

@mona//你好,谢谢你的帮助!但是很抱歉,我不理解你的问题?好的,我发现解决方案很简单。我必须写下:私有浮动宽度=getWindowManager.getDefaultDisplay.getWidth,高度=getWindowManager.getDefaultDisplay.getHeight//Ns permet de savoir la resolution而不是this:float width=this.getWidth,height=this.getHeight//我能把问题写下来解决吗you@Mona//请为我做这件事,因为如果我想发布我的答案,我需要等待9个小时。所以,请为我的答案,并张贴它将很酷;
private float width = getWindowManager().getDefaultDisplay().getWidth()
height = getWindowManager().getDefaultDisplay().getHeight();
//Ns permet de savoir la resolution instead of this: 
float width = this.getWidth()
height = this.getHeight();//Ns permet de savoir la resolution