简体   繁体   English

如何在Android中翻译动画后应用缩放动画

[英]How to apply Scale animation After Translate animation in android

Hi am doing one app here i need to apply rotate,move scale animation to my imageview..i tried using below code rotate and scale animation working well but in scale animation image is not scaling in where translate animation stoped that postion its coming back to original postion there its scaling..but i need to scale image where my image stoped using translate animation..where i did mistake any one suggest me thanks 嗨,我正在这里做一个应用程序,我需要在我的imageview上应用旋转,缩放动画。原始位置在那里缩放。但是我需要缩放图像,其中我的图像停止使用翻译动画。

public class MainActivity extends Activity {
    ImageView i1;
    TranslateAnimation moveLefttoRight1;
    Animation logoMoveAnimation;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        i1=(ImageView)findViewById(R.id.img);

        final Animation myRotation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotate1);
        i1.startAnimation(myRotation);

        moveLefttoRight1 = new TranslateAnimation(0, 0, 0, 200);
        moveLefttoRight1.setDuration(2000);
        moveLefttoRight1.setFillAfter(true);

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

            @Override
            public void onAnimationEnd(Animation animation) {
                i1.startAnimation(moveLefttoRight1);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });

        logoMoveAnimation = AnimationUtils.loadAnimation(this, R.anim.sacle); 



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

            @Override
            public void onAnimationEnd(Animation animation) {
                i1.startAnimation(logoMoveAnimation);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
    }
}

scale.xml: scale.xml:

<scale xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXScale="0.5"
    android:toXScale="2.0"
    android:fromYScale="0.5"
    android:toYScale="2.0"
    android:pivotX="0%"
    android:pivotY="100%"
    android:startOffset="0"
    android:duration="1000"
    android:fillAfter="true" />

rotate.xml rotation.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">

    <rotate android:fromDegrees="0"
        android:toDegrees="360"
        android:pivotX="50%"
        android:pivotY="50%"
        android:startOffset="0"
        android:duration="3000"/>
</set>

u may try after translation has finished img.setTranslation(value); 您可以在翻译完成后尝试img.setTranslation(value); value = the position where image should be after translation 值=平移后图像应位于的位置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM