I want to draw a rectangle using canvas which change its size with different screen size.
That means it increase of decrease its size with screen ratio.
I use the following code:
float scale = getContext().getResources().getDisplayMetrics().density;
canvas.drawRect(leftX-20*scale, leftY-20*scale, rightX+20*scale, rightY, mPaint);
But it does not change its size in different screen.
What can I do?
The problem is in
getContext().getResources().getDisplayMetrics().density;it wil give you same dencity always better use the following approachTo get density Use the following code
so your code will be