3

I try to set a custom animation between 2 layouts.

public class MainActivity extends FragmentActivity {

    View menu = null;
    ViewGroup parent = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_models);

        //initialize the container and his parent
        menu = findViewById(R.id.menu_model);
        parent = (ViewGroup) menu.getParent();

        //set transition
        LayoutTransition lt = new LayoutTransition();
        lt.enableTransitionType(LayoutTransition.CHANGING);
        parent.setLayoutTransition(lt);

        restoreMenu(null);
    }

    //display second menu
    public void changeMenu(View view) {

        int index = parent.indexOfChild(menu);
        View old = menu;
        menu = getLayoutInflater().inflate(R.layout.menu_2, parent, false);
        parent.addView(menu, index);
        parent.removeView(old);
    }

    //display first menu
    public void restoreMenu(View view) {

        int index = parent.indexOfChild(menu);
        View old = menu;
        menu = getLayoutInflater().inflate(R.layout.menu_1, parent, false);
        parent.addView(menu, index);
        parent.removeView(old);
    }
}

As you can see I'm using LayoutTransition with the LayoutTransition.CHANGING effect. But I want it looks like this:

My old menu is leaving to the left and my new menu is coming from the right.

Do you have any ideas how I could do that ? Does the LayoutTransition can do that ?

4

1 回答 1

0

定义滑入和滑出动画,TranslateAnimation然后使用

overridePendingTransition(int enterAnim, int exitAnim)

这个http://developer.android.com/reference/android/app/Activity.html#overridePendingTransition(int , int)

于 2013-07-25T13:10:19.487 回答