Ping应用程序动画Android

Ping应用程序动画Android,android,animation,Android,Animation,我只是好奇。当我启动/替换一个活动/片段时,如何在中实现动画。在IOS中,我们可以添加椭圆形的遮罩层并修改alpha值。如何在android中实现这一点?这是解决方案: 创建shape.xml: <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <s

我只是好奇。当我启动/替换一个活动/片段时,如何在中实现动画。在IOS中,我们可以添加椭圆形的遮罩层并修改alpha值。如何在android中实现这一点?

这是解决方案:

创建
shape.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid
        android:color="@android:color/black"/>
</shape>
然后创建两个动画
scale\u up.xml
scale\u down.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid
        android:color="@android:color/black"/>
</shape>
scale_up.xml
这是一个非常普遍的问题。你应该像Gaskoin建议的那样开始研究Android的过渡。如果你在那里遇到问题,尽管问。看看我的解决方案。
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:toXScale="1.5"
        android:toYScale="1.5"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="1000"
        android:fillBefore="true" />
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:fromXScale="1.5"
        android:fromYScale="1.5"
        android:toXScale="1.0"
        android:toYScale="1.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="1000"
        android:fillBefore="true" />
</set>
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final ImageView ping = (ImageView) findViewById(R.id.ping);

    final Animation scaleDown = AnimationUtils.loadAnimation(this, R.anim.scale_down);
    final Animation scaleUp = AnimationUtils.loadAnimation(this, R.anim.scale_up);

    scaleDown.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            ping.startAnimation(scaleUp);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

    scaleUp.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            ping.startAnimation(scaleDown);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

    ping.startAnimation(scaleUp);
}