简体   繁体   中英

animate list view divider

Scenario: I need a line between items in list view and want to apply animation (like slide from left).

Well, I customized list view divider. Now wanted to animate it.

Is there a possible way?

If not, suggest any alternative.

You better add the divider to your row layout to handle it. It will be display to each row in the listView then, use onTouchListner on your dividerObject (linearLayout) to initialize your Gesture Class :

_dividerRow.setOnTouchListener(new MyGestureListener()
                );


class MyGestureListener implements OnTouchListener
{
    private PointF _init;
    @Override
    public boolean onTouch(View v, MotionEvent event)
    {
        switch(event.getAction())
        {
            case MotionEvent.ACTION_DOWN :
                _init = new PointF(event.getRawX(), event.getRawY());
                if(!(v == null))
                {
                    _VelocityTracker = VelocityTracker.obtain();
                    _VelocityTracker.addMovement(event);
                }

                break;

            case MotionEvent.ACTION_UP :
                break;

            case MotionEvent.ACTION_MOVE :
                if(leave == false)
                {
                    if(event.getX() > 0)
                    {
                        _VelocityTracker.addMovement(event);
                        float diffX = event.getRawX() - _init.x;
                        float diffY = event.getRawY() - _init.y;

                        if (Math.abs(diffX) > _slop && Math.abs(diffX) > Math.abs(diffY))
                        {
                            _swipping = true;
                            ((ViewGroup) v).requestDisallowInterceptTouchEvent(true);

                            MotionEvent cancelEvent = MotionEvent.obtain(event);
                            cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (event.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT));
                            v.onTouchEvent(cancelEvent);
                        } 

                        if(_swipping == true)
                        {
                            ViewHelper.setTranslationX(v, diffX);
                        }
                    }
                }

                break;
            }

            return false;
        }
    }

Hope it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM