我有2个圆圈按钮,当我将手指移到它们上面时会显示一条消息。但是唯一的问题是按钮的下半部分没有注册为按钮。因此,当我在按钮底部附近移动手指时,不会显示该消息。另外,如果我将手指移到按钮上方一点,当手指不在按钮上时,它会在按钮中显示。
任何帮助将不胜感激!
我的代码:
矩形rect1; 矩形rect2;
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
rect1 = new Rect(buttonOne.getLeft(), buttonOne.getTop(),
buttonOne.getRight(), buttonOne.getBottom());
rect2= new Rect(buttonTwo.getLeft(), buttonTwo.getTop(),
buttonTwo.getRight(), buttonTwo.getBottom());
}
case MotionEvent.ACTION_MOVE:
Log.d(TAG, " coordinates are " + event.getX() + " , " + event.getY());
if (event.getActionMasked() == (MotionEvent.ACTION_DOWN | MotionEvent.ACTION_MOVE)) {
if (rect1.contains((int) event.getX(), (int) event.getY())) {
System.out.println(" in button1!!!!: ");
}
}
if (event.getActionMasked() == (MotionEvent.ACTION_DOWN | MotionEvent.ACTION_MOVE)) {
if (rect2.contains((int) event.getX(), (int) event.getY())) {
System.out.println(" in button2!!!!: ");
}
}
break;
我的XML:
<Button
android:id="@+id/buttonOne"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:layout_marginRight="192dp"
android:layout_marginBottom="306dp"
android:background="@drawable/circle_button" />
<Button
android:id="@+id/buttonTwo"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:layout_marginRight="106dp"
android:layout_marginBottom="126dp"
android:background="@drawable/circle_button2"
android:text="Button Two" />