Tôi có một ứng dụng Android trong đó có Danh sách Xem Như thế này mộtxem danh sách Android Phải/trái swipes như nhật ký cuộc gọi
Bây giờ tôi muốn thực hiện hai hoạt động khác nhau ở bên phải/swipe Left of Danh mục tài liệu trong cùng một cách như thế nào mẹ đẻ nhật ký cuộc gọi làm việc
Ngay Vuốt danh sách
Tôi muốn loại swipes này. Có ai biết làm thế nào để làm cho nó xảy ra. Về cơ bản tôi wan để thực hiện SimpleOnGestureListener
.
Tôi đã đọc một bài trả lời bởi thưa ông GAVFling gesture detection on grid layout và sau đó tôi thành công trong việc thực hiện swipe trái và phát hiện swipe đúng nhưng điều duy nhất tôi không nhận được trên đó Danh sách mục swipe đã xảy ra.
Cập nhật 24 tháng 5 năm 2013
Bây giờ tôi có thể phát hiện hành động swipe sử dụng mã này -
SwipeDetector.java
/**
* Class swipe detection to View
*/
public class SwipeDetector implements View.OnTouchListener {
public static enum Action {
LR, // Left to right
RL, // Right to left
TB, // Top to bottom
BT, // Bottom to top
None // Action not found
}
private static final int HORIZONTAL_MIN_DISTANCE = 30; // The minimum
// distance for
// horizontal swipe
private static final int VERTICAL_MIN_DISTANCE = 80; // The minimum distance
// for vertical
// swipe
private float downX, downY, upX, upY; // Coordinates
private Action mSwipeDetected = Action.None; // Last action
public boolean swipeDetected() {
return mSwipeDetected != Action.None;
}
public Action getAction() {
return mSwipeDetected;
}
/**
* Swipe detection
*/@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
{
downX = event.getX();
downY = event.getY();
mSwipeDetected = Action.None;
return false; // allow other events like Click to be processed
}
case MotionEvent.ACTION_MOVE:
{
upX = event.getX();
upY = event.getY();
float deltaX = downX - upX;
float deltaY = downY - upY;
// horizontal swipe detection
if (Math.abs(deltaX) > HORIZONTAL_MIN_DISTANCE) {
// left or right
if (deltaX < 0) {
mSwipeDetected = Action.LR;
return true;
}
if (deltaX > 0) {
mSwipeDetected = Action.RL;
return true;
}
} else
// vertical swipe detection
if (Math.abs(deltaY) > VERTICAL_MIN_DISTANCE) {
// top or down
if (deltaY < 0) {
mSwipeDetected = Action.TB;
return false;
}
if (deltaY > 0) {
mSwipeDetected = Action.BT;
return false;
}
}
return true;
}
}
return false;
}
}
Bây giờ sử dụng nó với ListView của bạn trong thời trang này
// Set the touch listener
final SwipeDetector swipeDetector = new SwipeDetector();
lv.setOnTouchListener(swipeDetector);
Trong bạn setOnItemClickListener
bạn có thể phát hiện các sự kiện swipe như thế này
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView <? > parent, View view,
int position, long id) {
if (swipeDetector.swipeDetected()) {
if (swipeDetector.getAction() == SwipeDetector.Action.LR) {
Toast.makeText(getApplicationContext(),
"Left to right", Toast.LENGTH_SHORT).show();
}
if (swipeDetector.getAction() == SwipeDetector.Action.RL) {
Toast.makeText(getApplicationContext(),
"Right to left", Toast.LENGTH_SHORT).show();
}
}
}
});
Nhưng tôi vẫn không thể để animate swipe như thế này:
có lẽ đây sẽ giúp http://stackoverflow.com/questions/11833504/simple-swipe-gesture- to-activity-tutorial – Elior
@Nikhil Agrawal có u nhận được giải pháp cho –
@Nikhil Agrwal: Tôi đang tìm kiếm tương tự, bạn có giải pháp nào cho vấn đề này không ?? – Jayesh