android - 如何快速更改图片资源?

标签 android

我想让它一旦我按下一个按钮,它就会移动并通过快速交换 imageview 中间动画的 src 来制作动画。

我试过使用 Thread.sleep 。

first.setImageResource(R.drawable.cata2);
                first.setImageResource(R.drawable.catb2);

对象动画代码

x += 10
first.setImageResource(R.drawable.cata2);
                ObjectAnimator d = ObjectAnimator.ofFloat(first, "translationX", x);
                d.setDuration(50);
                d.start();

它总是只是切换到 cata2。

最佳答案

Try this one. If the changing image resource not working, try to change it in background resource. Just adjust some duration and the thread sleep.

在 C# 中:

尝试将这些全部放在按钮的监听器中

设置动画

var clockwise = AnimationUtils.LoadAnimation(this.Activity, Resource.Animation.clockwise); clockwise.Duration = 2000;

将您的第一个设置为 cata2

this.Activity.RunOnUiThread(() =>
{
first.setImageResource(R.drawable.cata2);
});

从cata2到catb2随动画变化

Thread t = new Thread(delegate ()

{

first.StartAnimation(clockwise);

Thread.Sleep(500);

this.Activity.RunOnUiThread(() =>

{

first.setImageResource(R.drawable.catb2);

first.ClearAnimation();

return;

});

});

t.Start();

关于android - 如何快速更改图片资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57717022/

相关文章:

android - Android 上符合 OpenGL-ES 2.0 要求的最小纹理尺寸?

android - 如何在 android 中生成 OAuth 随机数?

android - 自动授予 Uri 权限

带有客户端证书的android webview

android - 在 ListView 中添加倒数计时器会在每个新行中重新启动

android - 无法实例化 GcmBroadcastReceiver

android - 在Android应用上搜索和播放YouTube视频

android - phonegap 3.0 想要 android 17,但我想要 android 18

java - 如何等待 requestLocationUpdates() 回调 Intent 完成?

android - 为什么 Memory Profiler 中的 "Code"和 "Native"部分使用太多内存,我该如何减少它?