检索坐标ImageView的

检索坐标ImageView的

本文介绍了检索坐标ImageView的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有可能得到的坐标,留下了ImageView的和顶部。我有2的ImageView内的滚动型一个RelativeLayout的内部。我试图获取的ImageView的矩阵矩阵= _iv.getImageMatrix(); ,但它是没有帮助的矩阵{[1.0,0.0,0.0 ] [0.0,1.0,0.0] [0.0,0.0,1.0]} 。有任何想法吗?难道有所作为,如果 getImageMatix()运行在不同的地方?

I would like to know if it is possible to get the coordinates, left and top, of an ImageView.I have 2 ImageView inside a RelativeLayout inside a ScrollView.I tried to retrieve the matrix of the ImageView with matrix = _iv.getImageMatrix(); but it is not helpful Matrix{[1.0, 0.0, 0.0][0.0, 1.0, 0.0][0.0, 0.0, 1.0]}.Any ideas? Would it make a difference if the getImageMatix() is run in a different place?

推荐答案

下面是一个更好的方式来做到这一点。我实现在ImageView的本身和X的OnTouchListener,Y坐标在相应于ImageView的

Here's a better way to do it. I implemented an OnTouchListener in the ImageView itself and the X,Y coordinates are corresponding to the ImageView.

_iv.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            //Choose which motion action has been performed
            switch(event.getAction())
            {
            case MotionEvent.ACTION_DOWN:
                //Get X, Y coordinates from the ImageView
                int X = (int) event.getX();
                int Y = (int) event.getY();

                //Do something

                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                break;
            }
            return true;
        }
}); //End setOnTouchListner()

这篇关于检索坐标ImageView的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 12:42