私はピアノアプリを実装しようとしているので、2つの白鍵画像と黒鍵画像の間にあります。rect はこれら 3 つの画像に関連付けられており、onTouchListener メソッドで黒鍵を押すと getHitRect() 関数が 3 つの値すべてを提供し、3 つのサウンドがすべて一度に再生されます。外側の画像ボタン、つまり黒鍵の座標のみを考慮し、その音符のみを再生するには、どのような変更を加える必要がありますか。画像が重なっていない白鍵に有効です。
どんな助けでも大歓迎です...
myButtons = new ArrayList<ImageView>();
myButtons.add(img_c); //white key1
myButtons.add(img_db); //black key
myButtons.add(img_d); //white key2
getWindow().getDecorView()
.findViewById(android.R.id.content)
.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View arg0, MotionEvent event) {
int action = event.getAction();
if (action != MotionEvent.ACTION_DOWN
&& action != MotionEvent.ACTION_MOVE
&& action != MotionEvent.ACTION_UP) return false;
Rect hitRect = new Rect();
ImageView button;
for(int i = 0; i < myButtons.size(); i++) {
button = myButtons.get(i);
button.getHitRect(hitRect);
if (hitRect.contains((int)event.getX(), (int)event.getY())) {
if(action==MotionEvent.ACTION_DOWN)
{
//play the sound
}
});