3

シェイプまたはボタンを作成したいのですが、クリックするとその背後にあるビューにイベントが送信されます。onInterceptTouchEvent を使用しましたが、それでもイベントはビューではなくボタンによって取得されます。これは私のコードです:

<?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;
  }

}

ありがとう

4

4 に答える 4

0

ボタンのサイズと位置に合わせてRectangle変数を作成し、次のように使用できます。

If(touch != null && rectangle.contains(touchPoint))
{
    // do action      
}  

ボタンを更新する前にこれを更新すると、長方形が新しい非表示のボタンになります。

于 2012-12-11T15:34:47.963 に答える
0

Buttonを拡張し、Button.onTouchEvent()でfalseを返す必要があります

new Button(dozActivity) {
@Override
public boolean onTouchEvent(MotionEvent event)
{
    return false;
}
};

または、ボタンの後ろにあるビューをOnTouchListenerに通知します。

于 2012-12-11T13:39:14.947 に答える
0

ボタンにこれを追加して、この問題を修正しました。

android:clickable = "false"

ご協力いただきありがとうございます

于 2012-12-11T14:28:41.947 に答える
0
@Override 
    public boolean hasWindowFocus() {
            return isEnabled() && getVisibility() == VISIBLE ? true : false;
        }

MultiTouchView クラスで。これがうまくいくことを願っています

于 2012-12-11T13:29:38.053 に答える