gpt4 book ai didi

java - 如何在android中动画结束后隐藏图像

转载 作者:行者123 更新时间:2023-12-01 06:53:04 25 4
gpt4 key购买 nike

在我的 Android 应用程序中,当我单击其中任何一个所有图像都具有动画效果时,我有五个 ImageView 。我为所有图像设置了缩小和放大动画。动画完成后,所选 ImageView 将不可见。图像不可见后,当我单击该 ImageView 位置时,它再次启动动画并且图像不可见。

放大动画:

<scale  xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="1"
android:toXScale="5"
android:fromYScale="1"
android:toYScale="5"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000"
android:fillAfter="true">
</scale>

缩小动画

<scale  xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="5"
android:toXScale="1"
android:fromYScale="5"
android:toYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000"
android:fillAfter="true">
</scale>

zoomin =AnimationUtils.loadAnimation(this, R.anim.zoom);
zoomout=AnimationUtils.loadAnimation(this, R.anim.zoomout);

ImageView v2 = (ImageView) findViewById(R.id.image2);

v2.setOnClickListener(new View.OnClickListener()
{
@Override public void onClick(View v)
{

v2.setAnimation(zoomin);
v2.startAnimation(zoomin);
v2.setAnimation(zoomout);
v2.startAnimation(zoomout);
v2.clearAnimation();
}
});

最佳答案

将此代码添加到您的动画对象中:

animation.setAnimationListener(new AnimationListener() 
{

@Override
public void onAnimationStart(Animation animation) { }

@Override
public void onAnimationRepeat(Animation animation) { }

@Override
public void onAnimationEnd(Animation animation)
{
v2.setImageResource(R.drawable.some_transparent_image);

}
});

关于java - 如何在android中动画结束后隐藏图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19921968/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com