触摸隐形视图后面的按钮

时间:2023-01-17 14:16:36

触摸隐形视图后面的按钮

See the picture, i have a button and it is behind an invisible view (the red line), lets say a gridview, or just simply LinearLayout. Is there any possible way that will let me touch or click the button behind this invisible view? Thank you.

看到图片,我有一个按钮,它在一个不可见的视图(红线)后面,让我们说一个gridview,或者只是简单的LinearLayout。有没有可能的方法让我触摸或点击这个看不见的视图背后的按钮?谢谢。

NOTE : i have my reason why i need the button behind the view, i just illustrated it using this picture for you guys to know what i meant. The button has to behind the view :))

注意:我有理由为什么我需要视图后面的按钮,我只是用这张图片说明它让你们知道我的意思。按钮必须在视图后面:))

3 个解决方案

#1


6  

android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"

Declare it in your layout.

在你的布局中声明它。

Let me know if it helps you.

如果它对您有所帮助,请告诉我。

#2


2  

Yes Its possible. Until or unless your invisible view is not clickable. so check your invisible layout structure. make android:clickable="false"

是的可能。直到或除非您的隐形视图不可点击。所以检查你的隐形布局结构。 make android:clickable =“false”

#3


0  

1 way you can do this is: 1. add an onTouch(View view, MotionEventevent) Listener to your layout 2. get the buttons bounds 3. Check if the touch event was done inside the bounds

您可以这样做的一种方法是:1。将onTouch(视图视图,MotionEventevent)监听器添加到您的布局2.获取按钮边界3.检查触摸事件是否在边界内完成

The code should look something like this:

代码看起来应该是这样的:

Button button;
Rect rect;

onCreate(){
rect = button.getClipBounds();
layout.setOnTouchListener(this)
}

onTouch(View view, MotionEvent event){
    if(rect.contains(event.getX(), event.getY())
        //insert action here
}

#1


6  

android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"

Declare it in your layout.

在你的布局中声明它。

Let me know if it helps you.

如果它对您有所帮助,请告诉我。

#2


2  

Yes Its possible. Until or unless your invisible view is not clickable. so check your invisible layout structure. make android:clickable="false"

是的可能。直到或除非您的隐形视图不可点击。所以检查你的隐形布局结构。 make android:clickable =“false”

#3


0  

1 way you can do this is: 1. add an onTouch(View view, MotionEventevent) Listener to your layout 2. get the buttons bounds 3. Check if the touch event was done inside the bounds

您可以这样做的一种方法是:1。将onTouch(视图视图,MotionEventevent)监听器添加到您的布局2.获取按钮边界3.检查触摸事件是否在边界内完成

The code should look something like this:

代码看起来应该是这样的:

Button button;
Rect rect;

onCreate(){
rect = button.getClipBounds();
layout.setOnTouchListener(this)
}

onTouch(View view, MotionEvent event){
    if(rect.contains(event.getX(), event.getY())
        //insert action here
}