如何改变点的位置,每屏分辨率?分辨率、位置

2023-09-06 11:25:26 作者:忘卜掉的曾经

假如我把一些点作为(X1,Y1)=(133123),(X2,Y2)=(149136),(X3,Y3)=(182136)等,这使得形状是这样的:

Suppose I put some points as (x1,y1) = (133,123), (x2,y2) = (149,136), (x3,y3) = (182,136) and so on which makes a shape something like this:

现在我想改变这些点的位置,按照屏幕分辨率,这样的形状被调整,并得到集中,也使得形状不被损坏。请帮我。

Now I want to change the position of these points as per the screen resolution such that the shape gets resized and gets centered and also such that the shape doesn't get damaged. Please help me.

推荐答案

您可以抓住从比例因子 DisplayMetrics 作为的 Android的 - 支持多种屏幕文档:

You can grab the scale factor from the DisplayMetrics as shown in the Android - Supporting Multiple Screens documentation:

final float scale = getResources().getDisplayMetrics().density;

乘以你的x和与 y坐标比例和你点屏幕密度无关。

要适应屏幕上的图像(或查看可能),你可以抓住的宽度和的高度您的视图。检查图像的宽度和高度,并计算最大比例因子。

To fit the image on the screen (or View probably), you can grab the width and height of your View. Check the width and height of your image and calculate the maximum scale factor.

联合(乘)两者的比例因子和你的形象应该适合你的视图。

Combine (multiply) both scale factors and your image should fit your View.