I need to draw an exact square 3x3 cm on the screen, you need the exact dimensions in any type of screen as design work.
The result in a Samsung Ace is 2.8 cm, the result is not exact.
Java...
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
float ld = 30 * metrics.densityDpi * (metrics.density/25.4f);
bitmap = Bitmap.createBitmap((int) ld, (int) ld, Bitmap.Config.ARGB_8888);
canvas = new Canvas(bitmap);
paint = new Paint();
paint.setColor(Color.WHITE);
imageView.setImageBitmap(bitmap);
canvas.drawRect(0, 0, (float) ld, (float) ld, paint);
XML...
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/image_view"
android:scaleType="center"/>
thank you very much