onTouchListener为整个画面画面、onTouchListener

由网友(何拆)分享简介:我充满按钮的屏幕,但希望onTouch法使用整个屏幕的坐标。我第一次尝试使用RelativeLayout的有onTouchListener,但从来没有设法使之与监听器连接(当屏幕被触摸,即什么都没有发生),我也试图把在屏幕上方的ImageView的,然后让这个观点无形I have a screen filled wi...

我充满按钮的屏幕,但希望onTouch法使用整个屏幕的坐标。我第一次尝试使用RelativeLayout的有onTouchListener,但从来没有设法使之与监听器连接(当屏幕被触摸,即什么都没有发生),我也试图把在屏幕上方的ImageView的,然后让这个观点无形

I have a screen filled with buttons, but want the onTouch-method to use the entire screen's coordinates. I first tried using a RelativeLayout with an onTouchListener, but never managed to make it "connect" with the listener (i.e. nothing happened when screen was touched), I also tried putting an ImageView on top of the screen, and then making this view invisible.

这最后的方法给了onClicks正确的反应,但我从来没有设法使不可见。

This last method gave correct responses to onClicks, but I never managed to make it invisible.

如果这是最好的解决方案,我很怀疑,我怎么做的ImageView完全看不见,又不失其onTouchListener(我已经尝试用白色的backgroundColor和setAlpha(0))。

If this is the best solution, which I highly doubt, how do I make the ImageView totally invisible, without losing its onTouchListener (I've experimented with white backgroundColor and setAlpha(0)).

我可以以某种方式使onTouchListener反应到整个屏幕,采用全局坐标,而屏幕是显示(和改变)几个按钮(preferably没有看不见的ImageView的)?

Can I somehow make the onTouchListener react to the whole screen, using global coordinates, while the screen is showing (and altering) several buttons (preferably without the invisible imageview)?

如果你不明白我在问什么的,随时可抱怨的了。根据需要,我会尽力填补国内空白。

If you don't understand what I'm asking for, feel free to complain about that. I'll try to fill the gaps as needed.

编辑:

我现在已经设法通过使用常规的onTouch法来解决问题。我跑进使得无论ACTION_DOWN和ACTION_MOVE激活按钮几个问题,但我终于得到了它的工作。对于其他人阅读本:onInterceptTouchEvent可能可以使用(但我从来没有想出如何让屏幕坐标,而不是视图坐标)

I've now managed to resolve the issue by using the regular onTouch-method. I ran into several problems making both ACTION_DOWN and ACTION_MOVE activate the buttons, but I finally got it working. For other people reading this: onInterceptTouchEvent could possibly be used (but I never figured out how to get the screen coordinates instead of the view-coordinates).

推荐答案

很抱歉,如果我错了,但我相信我刚刚也有类似的问题。我想所显示的图片,在该说的话画面点击继续或类似标题画面。我把事情搞糟逛了一下,发现你可以做一个布局的点击。

Sorry if I'm wrong, but I believe I've just had a similar problem. I wanted a title screen that displayed a picture and on the picture words that say "Click to go on" or something similar. I messed around for a bit and found that you can make a layout clickable.

    android:focusable="true" 
    android:id="@+id/titlescreenframe">

是我对我的布局xml文件。背景图像是简单地在后台属性(我知道你不使用图片)

is in my xml file for my layout. The background image is simply in the background attribute (I realize you aren't using images)

不管怎样,回到我的活动

Anyway, back in my activity

    private FrameLayout fl;
    ...
    fl = (FrameLayout)findViewById(R.id.titlescreenframe);
    fl.setOnClickListener(this);

然后我用switch语句来处理,并且是在一个布局的按钮。在这里,如果你需要它:Using switch语句来处理按钮点击声

看来这应该与其他布局工作,以及,我没有在我的主要布局字面上的任何意见。 (除非布局本身算作一个?)

Seems this should work with other layouts as well, and I don't have literally any views on my main layout. (unless the layout itself counts as one?)

哈!刚才你说你找到了解决办法实现。傻时机。我会后在场外机会,这可以帮助别人,快乐编码的每一个人。 :)

Ha! Just realized you said you found the solution. Silly timing. I'll post on the off-chance this helps someone, happy coding everyone. :)

阅读全文

相关推荐

最新文章