2017-06-29 5 views
-2

私は自分のアプリでマルチタッチをしようとしていますが、ボタンをタッチして画面を保持することはできません。私は画面の非ボタン部分に指があってもボタンを反応させたい。しかし、画面が押されていて、ボタンが押されていると画面が動かない場合、ボタンは機能しません。私のコードに似ています。アンドロイド - ボタンのクリックと画面のタッチが一緒に機能しない

package com.example.amitjoshi.am6; 
import android.graphics.Color; 
import android.support.v4.view.GestureDetectorCompat; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.TextView; 
import android.widget.Button; 
import android.widget.RelativeLayout; 
import android.view.MotionEvent; 
import android.view.GestureDetector; 
public class MainActivity extends AppCompatActivity implements 
GestureDetector.OnGestureListener{ 
    private TextView message; 
    private Button button; 
    private GestureDetectorCompat gestureDetector; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     RelativeLayout layout = 
(RelativeLayout)findViewById(R.id.layout); 
     layout.setBackgroundColor(Color.RED); 
     RelativeLayout.LayoutParams buttonDetails = new 
RelativeLayout.LayoutParams(
       RelativeLayout.LayoutParams.WRAP_CONTENT, 
       RelativeLayout.LayoutParams.WRAP_CONTENT 
     ); 
    buttonDetails.addRule(RelativeLayout.CENTER_HORIZONTAL); 
    buttonDetails.addRule(RelativeLayout.CENTER_VERTICAL); 
    message = (TextView)findViewById(R.id.message); 
    button = (Button)findViewById(R.id.button); 

    this.gestureDetector = new GestureDetectorCompat(this, this); 
    button.setOnClickListener(new ButtonListener()); 
    //gestureDetector.setOnDoubleTapListener(this); 
} 
private class ButtonListener implements View.OnClickListener{ 
    @Override 
    public void onClick(View view) { 
     MainActivity.this.message.setText("Clicked"); 
    } 
} 
@Override 
public boolean onDown(MotionEvent motionEvent) { 
    //message.setText("onDown"); 
    return false; 
} 

@Override 
public void onShowPress(MotionEvent motionEvent) { 
    //message.setText("onShowPress"); 
} 

@Override 
public boolean onSingleTapUp(MotionEvent motionEvent) { 
    message.setText("onSingleTapUp"); 
    return true; 
} 

@Override 
public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) { 
    message.setText("Swiped"); 
    return true; 
} 

@Override 
public void onLongPress(MotionEvent motionEvent) { 
    //message.setText("onLogPress"); 
} 

@Override 
public boolean onFling(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) { 
    message.setText("Swiped"); 
    return true; 
} 

@Override 
public boolean onTouchEvent(MotionEvent event) { 
    this.gestureDetector.onTouchEvent(event); 
    return super.onTouchEvent(event); 
} 
} 

答えて

0

は、私はあなたが持つことができない非ボタン

に指を持っている場合でも、ボタンが反応するようにしたいというフレームワークコンテナと。

+0

これを可能にする他のタイプの容器がありますか? –

+0

おそらく、それはまだ実行可能なので、システムはそのような機能を提供していません。 **この機能が本当に必要な場合は、自分自身で**を書くことができます –

+0

と私はそれをやり始めますか?私はどのクラスを拡張すべきですか? –

関連する問題