Making a ViewFlipper like the Home Screen using MotionEvent.ACTION_MOVE

前端 未结 2 935
粉色の甜心
粉色の甜心 2021-01-31 22:57

Ok I have a ViewFlipper with three LinearLayouts nested inside it. It defaults to showing the first one. This code:

// Assumptions in m         


        
相关标签:
2条回答
  • 2021-01-31 23:29

    Moving the view while you're moving your finger is easily done:

    case MotionEvent.ACTION_MOVE:
        final View currentView = vf.getCurrentView();
        currentView.layout((int)(touchEvent.getX() - oldTouchValue), 
                currentView.getTop(), currentView.getRight(), 
                currentView.getBottom());
    break;
    

    Now this only moves the current view, not the neighbors. I didn't test that yet, but those can probably be obtained by getChildAt:

    vf.getChildAt(vf.getDisplayedChild() - 1); // previous
    vf.getChildAt(vf.getDisplayedChild() + 1); // next
    

    Hope that helps.

    0 讨论(0)
  • 2021-01-31 23:32

    If I understand your request, this effect should now be implemented using a View Pager

    Looks like this:

    enter image description here

    0 讨论(0)
提交回复
热议问题