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

标签 android android-ndk

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

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

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

观察:

  • 我从另一个中的 ndk(c++ 到 java)获取 x 和 y 位置 线。函数 -> public void sendPointerCoords(float x, float y) 使用可运行的。

  • 我不能使用 Canvas 或 surface view,因为在我要去
    使用头部跟踪手势实现点击。

代码:

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]

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

faceTrackingThumbnail

最佳答案

如果你得到一个像这样的 ImageView :

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

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

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

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

必须更改您的 ImageView 位置并保持不变。如果您再次尝试 findViewById,它将重置其值。

关于android - 通过头部跟踪移动 android 鼠标指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30591125/

相关文章:

java - Android类设计

android - 动态单选按钮控件

android - 如何配置以使用 NDK 构建开源库?

android - Android支持setjmp/longjmp、access、chdir、getcwd吗?

android - C 中的 Sum native 方法 - java.lang.UnsatisfiedLinkError : Native method not found

android - indic-text-renderer 使用 harfbuzz 和 freetype

Android AsyncTask 奇怪地发布重复项

java - 使用 Android (ndk) 在 C++ 中打开和读取文本文件

我的 EditText 中的 Android 换行符

c++ - 安卓NDK : Not picking up CPP includes