49.Android过渡动画的一个小练习

转载请注明出处 http://blog.csdn.net/qq_31715429/article/details/52710485
本文出自:猴菇先生的博客

Android过渡动画是在api21加入的作用在window的动画,效果如下
49.Android过渡动画的一个小练习_第1张图片
1.在style的theme中加上

<item name="android:windowContentTransitions">trueitem>
<item name="android:windowAllowEnterTransitionOverlap">falseitem>
<item name="android:windowAllowReturnTransitionOverlap">falseitem>

2.MainActivity.java:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setWindowAnimation();
        findViewById(R.id.next_btn).setOnClickListener(new View.OnClickListener() {

            @SuppressWarnings("unchecked")
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, NextActivity.class);
                //这两个Pair是设置共享元素,transitionName需要和下一个界面中需要共享的控件设置相同的
                ActivityOptionsCompat activityOptionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation
                        (MainActivity.this, new Pair<>(findViewById(R.id.circle_iv), getString(R.string.share_circle))
                                , new Pair<>(findViewById(R.id.hello_tv), getString(R.string.share_text)));
                startActivity(intent, activityOptionsCompat.toBundle());
            }
        });
    }

    private void setWindowAnimation() {
        Slide slide = new Slide();//滑动动画
        slide.setSlideEdge(Gravity.LEFT);//设置滑出方向
        slide.setDuration(500);
        getWindow().setReenterTransition(slide);//重新进入
        getWindow().setExitTransition(slide);//离开
    }
}

3.NextActivity.java:

public class NextActivity extends AppCompatActivity {

    private static final int DELAY = 100;
    private static final int MODE_IN = 0x1;
    private static final int MODE_OUT = 0x2;

    private List

4.changebounds_with_arcmotion.xml


<transitionSet xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:interpolator="@android:interpolator/accelerate_decelerate">
    <changeBounds />
    
    <arcMotion
        android:maximumAngle="90"
        android:minimumHorizontalAngle="90"
        android:minimumVerticalAngle="0" />
transitionSet>

你可能感兴趣的:(Android)