【问题标题】:Efficient way to request touch focus from WindowManager?从WindowManager请求触摸焦点的有效方法?
【发布时间】:2011-08-21 12:55:14
【问题描述】:

我在 FrameLayout 上创建了两个视图,并请求将焦点放在第二个。当我开始活动时,触摸事件会挂起一段时间,然后传递到我的 GL 视图。我认为这需要随机时间(通常为 5-10 秒)。有办法刷新事件队列吗?

我有一个 GLSurfaceView,我想在它上面绘制一个覆盖 SurfaceView。 SurfaceView 必须绘制在 GLSurfaceView 之上,但输入事件必须传递到 opengl 表面。 这是我的活动,

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mGLView= new SFView(this);
    mCanvas= new SFCanvas(this);

    mLayout=new FrameLayout(this);
    mLayout.addView(mCanvas);
    mLayout.addView(mGLView);

    setContentView(mLayout);


    mGLView.post(new Runnable() {
        public void run() {
        while( mGLView.isFocused() == false )
           {
                mGLView.requestFocus();
           }
        }
    });
}

我的 Logcat 看起来像这样。

KeyInputQueue        Enqueueing touch event1
KeyInputQueue        Enqueueing touch event0
KeyInputQueue        Enqueueing touch event1
KeyInputQueue        Enqueueing touch event0
KeyInputQueue        Enqueueing touch event1
KeyInputQueue        Enqueueing touch event0
..
WindowManager        Delivering pointer 1 > Window{com.myapplication/com.myapplication.activity}
WindowManager        Delivering pointer 0 > Window{com.myapplication/com.myapplication.activity}
WindowManager        Delivering pointer 1 > Window{com.myapplication/com.myapplication.activity}
KeyInputQueue        Enqueueing touch event0
WindowManager        Delivering pointer 0 > Window{com.myapplication/com.myapplication.activity}
KeyInputQueue        Enqueueing touch event1
WindowManager        Delivering pointer 1 > Window{com.myapplication/com.myapplication.activity}
..

我也试过一个 requestFocus() ,但效果相同 应用程序在活动开始的第一秒变得不负责任。我哪里错了? 感谢所有建议。 对于我的错误解释和我的语言,我很抱歉。我是android平台和这个网站的新手。

【问题讨论】:

  • 我还重新实现了onTouchEvent(),两个视图都没有调用这个方法。

标签: android events focus overlay


【解决方案1】:

我发现了我犯的错误。 我在视图构造函数中加载资源。它阻止了android做事。 我已将资源加载迁移到子线程中,并修复了一些问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-04
    • 1970-01-01
    • 1970-01-01
    • 2011-12-26
    相关资源
    最近更新 更多