Я хотел бы изменить масштаб анимации с некоторой задержкой времени, прежде чем обратная анимация ниже - это код, который работает для обратного с бесконечным, но мне нужно установить промежуток времени, анимацииОбратный Zoomin Анимация с некоторым заданным промежутком времени для просмотра изображений
zoom_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:repeatMode="reverse"
android:duration="5000"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="2"
android:toYScale="2" >
</scale>
zoomout.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="5000"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.5"
android:toYScale="0.5" >
</scale>
Это моя деятельность с анимацией
public class MainActivity extends AppCompatActivity {
public static final String TAG= "MainActivity";
Animation zoomin, zoomout; //declared as public
private final int ANIM_HOLD_LENGTH = 2000;
ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView= (ImageView) findViewById(R.id.imageView);
zoomin = AnimationUtils.loadAnimation(this, R.anim.zoomin);
zoomout = AnimationUtils.loadAnimation(this, R.anim.zoomout);
imageView.setAnimation(zoomin);
zoomin.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
Log.d(TAG,"onAnimationStart--");
}
@Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
Log.d(TAG,"onAnimationRepeat--");
}
@Override
public void onAnimationEnd(final Animation arg0) {
Log.d(TAG,"onAnimationEnd--");
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Log.d(TAG,"onAnimationEnd-- run");
imageView.startAnimation(zoomout);
}
}, ANIM_HOLD_LENGTH);
}
});
zoomout.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation arg0) {
Log.d(TAG,"zoomout onAnimationStart--");
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation arg0) {
Log.d(TAG,"zoomout onAnimationEnd--");
imageView.startAnimation(zoomin);
}
});
}
}
Спасибо за ваш ответ omer, я могу это сделать, но я не смог найти способ удержания и воспроизведения обратной анимации – kondal
, вы можете создать еще один zoom_in_reverse.xml для обратной анимации и начать с onAnimationEnd zoom_in, добавив задержку – Omer
Я сделал то же изображение, но изображение возвращается в нормальное место, а затем запускается, что zoom_in_reverse animation – kondal