通过头部跟踪移动 android 鼠标指针

Move android mouse pointer by head tracking

我正在开发一个与 android 界面交互的应用程序 对于那些无法在移动设备上与他的手互动的人。

算法是基于头部跟踪的,我解决了这个问题。

所以,我需要知道如何移动 android 指针,或者如何通过布局设置可绘制对象或任何视图位置,无论我是否从另一个线程获取位置坐标。

观察:

代码:

public void sendPointerCoords(float x, float y) {
        // TODO Auto-generated method stub
        final float xPos=x;
        final  float yPos=y;

        Log.v(LOG_TAG,"This are the coords ["+x+", "+y+"]");
        runOnUiThread(new Runnable() 
        {
            public void run() 
            {
                //red pointer is an image view and here chrashed when I try to move
                /*red_pointer.setPivotX(xPos);
                red_pointer.setPivotY(yPos);*/

            }
        });![enter image description here][1]

我用谷歌搜索,但没有找到满足我需求的解决方案。

如果您获得如下图片视图:

ImageView myImageView = (ImageView)findViewById(R.id.myImageViewId);

您可以通过 Xml 布局属性获得它。

如果你想改变他们的属性,你需要在你的activity中存储变量ImageView _myImageView 并修改它。喜欢:

runOnUiThread(new Runnable()
{
   public void run()
   {
      _myImageView.setX(xPos);
      _myImageView.setY(yPos);
   }
});
}

必须更改您的图片查看位置并留下来。如果您再次尝试 findViewById,它将重置其值。