To draw a square I use the replacement ImageView on the drawn Circle (Rectangle) .
Here is my code for creating an ImageView and drawing a circle:

imageView = new ImageView(getApplicationContext()); imageView.setId(R.id.imageViewCircle); imageView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)); ((RelativeLayout)swipe).addView(imageView); ImageView imageView=(ImageView) findViewById(R.id.imageViewCircle); bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); canvas = new Canvas(bitmap); paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(Color.BLACK); canvas.drawCircle(50, 50, 40, paint); imageView.setImageBitmap(bitmap); 

That's what comes out for me:

(See Screenshot)

  • What's the problem? You draw what you get :) - Eugene Krivenja
  • What is the problem, what do you want to do, what is wrong? You can just show the circle in several ways and drawing the bitmap is not the best. - woesss

2 answers 2

It looks like ImageView scales your small image to full screen.

Try setting imageView.setScaleType(ImageView.ScaleType.CENTER)

  • Thank you for the answer. But I figured it out myself. - Twikoffin

If you just need “smoothness” within the boundaries of the circle - use anti-aliasing for the brush you paint:

 paint.setAntiAlias(true); 

To smooth text:

 paint.setSubpixelText(true); 

But note that the load on the device increases

And if you just need a circle in the background of the button, then it is better to create an xml file, for example yelow_circle.xml:

 <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="oval"> <solid android:color="#FFFF00"/> </shape> </item> </selector> 

A button to prescribe this background

  • he used anti-aliasing in the designer Paint - alex
  • A little bit wrong. But thanks for bothering you! - Twikoffin