Azuken Posted October 19, 2012 Share Posted October 19, 2012 Bonjour, Je voudrais dans mon application faire apparaître un cercle dans une View, seulement le cercle ne s'affiche pas. @SuppressLint("DrawAllocation") @Override protected void onDraw(Canvas canvas) { Paint paint = new Paint(); paint.setColor(Color.BLACK); float radius = 3; float cx = 2; float cy = 2; canvas.drawCircle(cx, cy, radius, paint); super.onDraw(canvas); } Une solution ? Azuken Link to comment Share on other sites More sharing options...
Azuken Posted October 22, 2012 Author Share Posted October 22, 2012 J'ai finalement réussi à trouver comment faire. package fr.test.appli_graphique; import android.annotation.SuppressLint; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.util.AttributeSet; import android.view.View; public class CircleView extends View { public CircleView(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub } public CircleView(Context context) { super(context); // TODO Auto-generated constructor stub } public CircleView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // TODO Auto-generated constructor stub } @SuppressLint("DrawAllocation") @Override protected void onDraw(Canvas canvas) { Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(Color.LTGRAY); float cx = getMeasuredWidth() / 2; float cy = getMeasuredHeight() / 2; float radius = Math.min(cx, cy); canvas.drawCircle(cx, cy, radius, paint); super.onDraw(canvas); } } Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.