动画触摸的Andr​​oid ListView的看法 [英] Animating Android ListView view on touch

查看:141
本文介绍了动画触摸的Andr​​oid ListView的看法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在的ListView当用户触摸项目动画项目和向后做动画当触摸已经结束。

I'd like to animate item in ListView when user touches the item and do the animation backwards when the touch have ended.

我试着通过覆盖 onTouchEvent 列表项的这样做,但如果我返回true,当我处理我没有收到该事件 OnItemClickListener 通话了,因为我已经消耗的触摸事件,如果我返回false当用户停止触摸的观点我没有收到回调。

I've tried doing it by overriding onTouchEvent of the list item but if I return true when I handle the event I don't receive OnItemClickListener calls anymore because I've consumed the touch event, and if I return false I don't receive callback when user stops touching the view.

    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                long id) {
            //handle onclick
        }
    });

@Override
public boolean onTouchEvent(MotionEvent event) {
    Log.v(TAG, event.getActionMasked() + "");
    if(event.getActionMasked() == MotionEvent.ACTION_DOWN) {
        Animation animation = createColorAnimation(false);
        animation.setDuration(500);
        startAnimation(animation);
        return true;
    } else if(event.getActionMasked() == MotionEvent.ACTION_UP || event.getActionMasked() == MotionEvent.ACTION_CANCEL) {
        Animation animation = createColorAnimation(true);
        animation.setDuration(500);
        startAnimation(animation);
        return true;
    }
    return super.onTouchEvent(event);
}

我想收到 ACTION_UP ACTION_CANCEL 事件 onTouchEvent 和通话 OnItemClickListener ,我该如何实现这一目标?

I want to receive ACTION_UP and ACTION_CANCEL events onTouchEvent and calls OnItemClickListener, how do I achieve this?

推荐答案

在方法getView()列表适配器。这绘制对象必须是有状态(isStatefull shound返回true),覆盖onStateChanged和日志StateSet.dump(stateSet),剩下的给你,你与每个国家做什么。

in your list adapter in method getView() before returning View v call v.setBackgroundDrawable with a custom Drawable. this Drawable has to be stateful (isStatefull shound return true), overwrite onStateChanged and log StateSet.dump(stateSet), the rest is up to you what you do with each state

这篇关于动画触摸的Andr​​oid ListView的看法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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