Android studio getRawX()和getRawY()以什么单位返回?

Android studio getRawX()和getRawY()以什么单位返回?,android-studio,Android Studio,我有一个100dp x 100dp大小的图像(树)。当我用手指抓取图像时,我希望我的手指位于图像的中心。问题是我不知道getRawX()和getRawY()以什么单位返回。X和Y的情况似乎有所不同。您可能会想: 即使它不“准确地”在中心,也有关系吗 -不是用于此应用程序,而是用于以后的使用(至少对我而言)和此应用程序的升级 这不是你可以在文档中找到的东西吗 -会有帮助的,但是不行,我哪儿都找不到。只是它返回一个整数。我看不懂,我不是程序员 为什么你对盲人和视力受损的人来说是个混蛋 -因为很难创建

我有一个100dp x 100dp大小的图像(树)。当我用手指抓取图像时,我希望我的手指位于图像的中心。问题是我不知道getRawX()和getRawY()以什么单位返回。X和Y的情况似乎有所不同。您可能会想:

即使它不“准确地”在中心,也有关系吗

-不是用于此应用程序,而是用于以后的使用(至少对我而言)和此应用程序的升级

这不是你可以在文档中找到的东西吗

-会有帮助的,但是不行,我哪儿都找不到。只是它返回一个整数。我看不懂,我不是程序员

为什么你对盲人和视力受损的人来说是个混蛋

-因为很难创建自定义视图,而且我再也不能看着黄色背景嘲笑我,比如“你不能解决这个问题”


事先谢谢你。

好的,我哥哥告诉我。以像素为单位。但我仍然不知道为什么它必须是非模拟的,才能处于画面的中心:

        public class Test_activity extends Activity {

        int screenWidth;
        int screenHeight;

        @SuppressLint("ClickableViewAccessibility") //Because I am a dick to blind and visually impaired people.
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_test_activity);

            WindowManager wm = getWindowManager();
            Display display = wm.getDefaultDisplay();
            Point size = new Point();
            display.getSize(size);
            screenWidth = size.x;
            screenHeight = size.y;

            final ImageView tree = findViewById(R.id.tree_id);

            tree.setOnTouchListener(new View.OnTouchListener() {

                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    LayoutParams layoutParams = (LayoutParams) tree.getLayoutParams();
                    if (event.getAction() == MotionEvent.ACTION_MOVE) {

                            int x_cord = (int) event.getRawX();
                            int y_cord = (int) event.getRawY();

                            if (x_cord > screenWidth) {
                                x_cord = screenWidth;
                            }
                            if (y_cord > screenHeight) {
                                y_cord = screenHeight;
                            }

                            layoutParams.leftMargin = x_cord - 100;
                            layoutParams.topMargin = y_cord - 200;

                            tree.setLayoutParams(layoutParams);

                    }

                    return true;
                }
            });
        }
    }

好的,我哥哥告诉我的。以像素为单位。但我仍然不知道为什么它必须是非模拟的,才能处于画面的中心:

        public class Test_activity extends Activity {

        int screenWidth;
        int screenHeight;

        @SuppressLint("ClickableViewAccessibility") //Because I am a dick to blind and visually impaired people.
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_test_activity);

            WindowManager wm = getWindowManager();
            Display display = wm.getDefaultDisplay();
            Point size = new Point();
            display.getSize(size);
            screenWidth = size.x;
            screenHeight = size.y;

            final ImageView tree = findViewById(R.id.tree_id);

            tree.setOnTouchListener(new View.OnTouchListener() {

                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    LayoutParams layoutParams = (LayoutParams) tree.getLayoutParams();
                    if (event.getAction() == MotionEvent.ACTION_MOVE) {

                            int x_cord = (int) event.getRawX();
                            int y_cord = (int) event.getRawY();

                            if (x_cord > screenWidth) {
                                x_cord = screenWidth;
                            }
                            if (y_cord > screenHeight) {
                                y_cord = screenHeight;
                            }

                            layoutParams.leftMargin = x_cord - 100;
                            layoutParams.topMargin = y_cord - 200;

                            tree.setLayoutParams(layoutParams);

                    }

                    return true;
                }
            });
        }
    }