Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - what is the right way to implement a wizard with an animation between the steps

I'm building and Android app that needs to go through steps like a wizard.

Current structure:

At the moment I'm using one activity with separate views.xml for each step, then I'm using setContentView(activeStep) to display the active step.

I ran into some difficulties when trying to animate between the steps. I used the following code:

LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(activeStep, null, false);
view.startAnimation(AnimationUtils.loadAnimation(activity, R.anim.slide_in));
setContentView(view);

The result: the first view was gone and the new one animated, not a smooth transition.

My goal is to animate both views, one slides out the other in.

Question: Is it possible to do it with my current structure (reminder: one activity, many views) or should I treat each step as a separate activity?

like image 894
Shlomi Schwartz Avatar asked Jan 09 '12 16:01

Shlomi Schwartz


People also ask

What can be used to animate between two or more views in Android?

The transitions framework can run animations between a starting and an ending scene. You can create your scenes from a layout resource file or from a group of views in your code. However, the starting scene for your transition is often determined automatically from the current UI.

What can be used to animate between two or more views?

Can be used to animate between two or more views? In Android, ViewAnimator is a sub class of FrameLayout container that is used for switching between views. It is an element of transition widget which helps us to add transitions on the views ( like TextView, ImageView or any layout).


1 Answers

I guess there is more the one way of implementing step progress with animation, here is how I did it:

private static ViewAnimator viewAnimator;

 public void onCreate(Bundle savedInstanceState) {
        viewAnimator = new ViewAnimator(this);
        View step1 = View.inflate(activity, R.layout.step_1, null);
        View step2 = View.inflate(activity, R.layout.step_2, null);
        View step3 = View.inflate(activity, R.layout.step_3, null);
        viewAnimator.addView(step1);
        viewAnimator.addView(step2);
        viewAnimator.addView(step3);
        viewAnimator.setInAnimation(activity, R.anim.slide_in);
        viewAnimator.setOutAnimation(activity, R.anim.slide_out);
        setContentView(viewAnimator);
    }

then clicking a button I call viewAnimator.showNext() and viewAnimator.showPrevious() ViewSwitcher was not good for my purpose, because it can hold only 2 views at a time

like image 72
Shlomi Schwartz Avatar answered Sep 27 '22 20:09

Shlomi Schwartz