我的程序中有下一個UI:ui。 我想在一組按鈕上處理手指輕掃事件,當然,不會失去單擊按鈕的能力。怎麼做?如何爲觸摸事件調用特殊區域?
1
A
回答
1
你說的是屏幕底部的按鈕?
下面是3個按鈕水平對齊的示例,可以輕掃並點擊。處理「onSingleTapUp」中的點擊和「onFling()」中的滑動。
public class SwipeExample extends Activity implements OnTouchListener {
private static final String TAG = SwipeExample.class.getName();
private int mOnTouchId;
private GestureDetector mGestureDetector;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mGestureDetector = new GestureDetector(new MyGestureDetector());
Button one = (Button) findViewById(R.id.button_one);
one.setOnTouchListener(this);
Button two = (Button) findViewById(R.id.button_two);
two.setOnTouchListener(this);
Button three = (Button) findViewById(R.id.button_three);
three.setOnTouchListener(this);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
mOnTouchId = v.getId();
if (mGestureDetector.onTouchEvent(event)) {
Log.d(TAG, "onTouchEvent");
}
return false;
}
private class MyGestureDetector extends SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
Log.d(TAG, "onFling() - MyGestureDetector");
return true;
}
@Override
public boolean onDown(MotionEvent e) {
Log.d(TAG, "onDown() - MyGestureDetector");
return true;
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
Log.d(TAG, "onSingleTapUp() - MyGestureDetector");
if (mOnTouchId == R.id.button_one) {
Log.d(TAG, "Button one");
} else if (mOnTouchId == R.id.button_two) {
Log.d(TAG, "Button two");
} else if (mOnTouchId == R.id.button_three) {
Log.d(TAG, "Button three");
}
return true;
}
}
}
main.xml中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/LinearLayout"
android:background="#348282">
<Button android:id="@+id/button_one" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Button one" />
<Button android:id="@+id/button_two" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Button two" />
<Button android:id="@+id/button_three" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Button three" />
</LinearLayout>
相關問題
- 1. 如何限制觸摸事件到特定區域或UIView?
- 2. 在box2d主體的特定區域觸摸事件
- 3. 如何檢測/處理彎曲區域上的觸摸事件?
- 4. UISwitch:使觸摸區域大於默認觸摸區域
- 5. HTML圖像地圖區域觸摸事件沒有觸發
- 6. 如何擴展按鈕觸摸區域?
- 7. 使用ngTouch定義觸摸事件的區域
- 8. 調度觸摸事件
- 9. 如何爲MKMapView創建觸摸事件?
- 10. 如何獲得特定的觸摸區域?
- 11. 如何檢測我觸摸特定區域?
- 12. WebView如何通過觸摸背後,但只在特定區域
- 13. UIButton的可觸摸區域
- 14. 獲取觸摸區域
- 15. iPhone - 觸摸區域檢測
- 16. 觸摸區域控制
- 17. Cocos2d按鈕觸摸區域
- 18. 爲UIPanGestureRecognizer增加觸摸區域?
- 19. 增加觸摸手勢區域爲UILabel
- 20. 如何在android中檢測開放區域的觸摸區域?
- 21. 如何調整相機api的觸摸對焦區域android
- 22. 在移動的UIView中通過區域傳遞觸摸事件
- 23. 當觸摸GUI的區域時,只有gui事件響應?
- 24. 在區域外彈出導航模式關閉觸摸事件
- 25. iOS取消某些區域的觸摸事件
- 26. 觸摸事件
- 27. 觸摸事件
- 28. 如何觸發觸摸事件?
- 29. 如何禁用觸摸事件android
- 30. 如何讓fabricJS使用觸摸事件?
你是說,你要處理它,如果在幾個按鈕或只是一個發生刷卡?當然,還有幾個當然是 – Maximus 2011-05-28 19:10:13
。例如顯示寬度的60%。 – Divers 2011-05-28 19:32:57