从 WindowManager 请求触摸焦点的有效方法?

发布于 2024-11-30 13:11:23 字数 1795 浏览 0 评论 0原文

我在 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平台和这个网站的新手。

I have created two views on a FrameLayout, and requested focus to second. When I start the activity touch events hangs up for a while, then passes to my GL view. This takes random time I think (generally 5-10 seconds). It there a way to flush event queue?

I have a GLSurfaceView and I want draw an overlay SurfaceView above it. SurfaceView must be drawn on top of GLSurfaceView but input events must be delivered to opengl surface.
This is my activity,

@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();
           }
        }
    });
}

and my Logcat looks like this.

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}
..

I've also tried a single requestFocus() , but it gave same effect
Application becomes irresponsible at first seconds activity starts. Where did I wrong?
Thanks for all suggestions.
I am sorry for misexplanation, and for my language. I am a newbie for android platform, and this site.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一抹苦笑 2024-12-07 13:11:23

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

I have found the mistake I did.
I was loading resources in views constructor. It was blocking android to doing stuff.
I've migrated resource loading into a child thread and problem fixed, a little.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文