Android的 - ListView的滑动左/右像三星接触的ListView [英] Android - ListView slide left/right like Samsung contact ListView

查看:129
本文介绍了Android的 - ListView的滑动左/右像三星接触的ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个应用程序,我需要一个像我的三星Galaxy S的conctact ListView的一个ListView:

I am developing an application, and I need a ListView like conctact ListView of my Samsung Galaxy S:

http://imgur.com/5MkPZ92

当我我的手指向右滑动,我可以发送邮件到该联系人。

When I slide my finger to the right I can send message to this contact.

当我我的手指向右滑动,我可以打电话给我联系。

When I slide my finger to the right I can call to my contact.

我有我的ListView和只需要功能做...

I have my ListView and only need the function for do it...

在此先感谢。

PD: 我搜索了很多,没有发现任何东西。最相似的: <一href="http://stackoverflow.com/questions/7308836/resource-for-android-slight-left-right-slide-action-on-listview">Resource对于Android轻微左/右滑式列表视图行动

PD: I searched a lot and have not found anything. The most similar: Resource for Android Slight Left/Right Slide action on listview

推荐答案

你也许在这里做什么是创建一个新的看法尤其是对列表视图(称之为ListViewFlinger或东西)。然后在此视图,覆盖其的onTouchEvent方法,并把一些code。在那里确定一个滑动的手势。一旦你的幻灯片的姿态,火onSlideComplete事件(你必须作出这样的监听器)的voialla,你一个ListView采用滑盖激活的内容。

What you might what to do here is create a new view especially for the list view (call it ListViewFlinger or something). Then in this view, override its onTouchEvent method and place some code in there to determine a slide gesture. Once you have the slide gesture, fire a onSlideComplete event (you'll have to make that listener) an voialla, you a ListView with slide activated content.

float historicX = Float.NaN, historicY = Float.NaN;
static final TRIGGER_DELTA = 50; // Number of pixels to travel till trigger

@Override public boolean onTouchEvent(MotionEvent e) {

    switch (e.getAction()) {
    case MotionEvent.ACTION_DOWN:
        historicX = e.getX();
        historicY = e.getY();
        break;
    case MotionEvent.ACTION_UP:
        if (e.getX() - historicX > -TRIGGER_DELTA) {
            onSlideComplete(Direction.LEFT);
            return true;
        }
        else if (e.getX() - historicX > TRIGGER_DELTA)  {
            onSlideComplete(Direction.RIGHT);
            return true;
        } break;
    default:
        return super.onTouchEvent(e);
    }
}

enum Direction {
    LEFT, RIGHT;
}

interface OnSlideCompleteListener {
    void onSlideComplete(Direction dir);
}

这篇关于Android的 - ListView的滑动左/右像三星接触的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆