gpt4 book ai didi

android - 如何单击 Android 中按钮后面的 View ?

转载 作者:太空狗 更新时间:2023-10-29 15:14:30 25 4
gpt4 key购买 nike

我想创建一个形状或按钮,但当它被点击时,它会将事件发送到它后面的 View 。我已经使用了 onInterceptTouchEvent 但事件仍然是由按钮而不是 View 获取的。这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/background">

<com.Example.MultitouchView
android:id="@+id/touchView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF0000" />

<Button
android:id="@+id/btnDo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg1"
android:text="Test"
android:textSize="20sp"
android:textColor="#110342" >
</Button>

</RelativeLayout>

MultitouchView.class

public class MultitouchView extends View {

private boolean isMultiTouch = false;
private static final int SWIPE_MIN_LENGHT = 100;
private static final long MULTITOUCH_DELAY = 500;
private long mTouchStart;

public MultitouchView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}

public MultitouchView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);

}

public MultitouchView(Context context, AttributeSet attrs) {
super(context, attrs);

}

public boolean onInterceptTouchEvent(MotionEvent event){
Toast toast = Toast.makeText(getContext(), "TEST", 1000);
toast.show();

return false;

}

@Override
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);
int action = event.getAction() & MotionEvent.ACTION_MASK;
switch (action) {
case MotionEvent.ACTION_DOWN: {
Log.d("MultitouchExample","Action Down");
mTouchStart = System.currentTimeMillis();
SoundManager.playSound(1,1);
break;
}
}
return true;
}

}

谢谢

最佳答案

@Override 
public boolean hasWindowFocus() {
return isEnabled() && getVisibility() == VISIBLE ? true : false;
}

在您的 MultiTouchView 类中。我希望这有效

关于android - 如何单击 Android 中按钮后面的 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13821422/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com