Android ViewFlipper + desktop animation

I am trying to use ViewFlipper and make it act like a home screen (the layout will be moved with my finger). Take a look at this for an example. I want to do this with a ViewFlipper that contains only two children, so I need to display the opposite view on both sides of the current view, depending on how the user moves his finger. This code works, but only for 1 direction at a time. This is onTouchEvent.

case MotionEvent.ACTION_MOVE: leftView.setVisibility(View.VISIBLE); rightView.setVisibility(View.VISIBLE); // move the current view to the left or right. currentView.layout((int) (touchEvent.getX() - oldTouchValue), currentView.getTop(), (int) (touchEvent.getX() - oldTouchValue) + 320, currentView.getBottom()); // place this view just left of the currentView leftView.layout(currentView.getLeft() - 320, leftView.getTop(), currentView.getLeft(), leftView.getBottom()); // place this view just right of the currentView rightView.layout(currentView.getRight(), rightView.getTop(), currentView.getRight() + 320, rightView.getBottom()); 

Which of the two bottom lines that I put is the last one, that the direction will work correctly, and the other will not.

This is how I set leftView and rightView:

 final View currentView = myFlipper.getCurrentView(); final View leftView, rightView; if (currentView == meView) { Log.d("current layout: ", "me"); leftView = youView; rightView = youView; } else if (currentView == youView) { Log.d("current layout: ", "you"); leftView = meView; rightView = meView; } else { leftView = null; rightView = null; } 

Is it possible to configure it so that the same view is shown on both sides of the current view?

+4
source share
4 answers

Thanks stealthcopter

New code worked here, if anyone is interested.

  if (touchEvent.getX() < oldTouchValue){ // place this view just right of the currentView rightView.layout(currentView.getRight(), rightView.getTop(), currentView.getRight() + 320, rightView.getBottom()); }else if (touchEvent.getX() > oldTouchValue) { // place this view just left of the currentView leftView.layout(currentView.getLeft() - 320, leftView.getTop(), currentView.getLeft(), leftView.getBottom()); } 

I also moved the calls to setVisibility () to MotionEvent.ACTION_DOWN, trying to get rid of some flickering views. It helped, but I still did a bit of work.

+1
source

I may not have a very constructive suggestion, but if you want it to behave like a home screen, why don't you want to look at src from this and change it to your needs?

0
source

To get rid of flickering, set setVisibility(View.INVISIBLE) to MotionEvent.ACTION_DOWN . The default value is "GONE" in the view. This means that you cannot set Layout() to view until it becomes โ€œvisibleโ€ or โ€œinvisibleโ€. So, in three stages:

  • Set visibility to INVIVIBLE in view
  • Set layout () in view
  • Set Visibility Visibility in a View
0
source

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

It looks like:

enter image description here

0
source

Source: https://habr.com/ru/post/1308275/


All Articles