Android版的ImageView与AnimationDrawable源代码更改大小 [英] Android Imageview with AnimationDrawable source changes size

查看:133
本文介绍了Android版的ImageView与AnimationDrawable源代码更改大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 我已经做了一组3的图像,将重新present一个动物的举动。再$ P $每个图像psents框架和仅与透明背景的动物组成。

  1. I have made a set of 3 images that will represent the move of a animal. Each image represents a frame and consists only in the animal with transparent background.

我已在code一AnimationDrawable并创建了动画:

I have made a AnimationDrawable in code and created the animation:

AnimationDrawable staticAnimation = new AnimationDrawable();
staticAnimation.addFrame(ctx.getResources().getDrawable("frame1"),150);
staticAnimation.addFrame(ctx.getResources().getDrawable("frame2"),150);
staticAnimation.addFrame(ctx.getResources().getDrawable("frame3"),150);


  • 我设置了​​动画作为一个ImageView的背景,并启动

  • I set the animation as a background for a Imageview and start it

    imgAnimal.setBackgroundDrawable(staticAnimation );
    staticAnimation.start()


  • 由于帧有不同的宽度(图需要重新步移动)看起来像ImageView的大小调整的动画图像。不如说,如果帧1是更大然后式2,第1帧显示正常,但2架被拉伸到那样大frame1的了。看起来真的很可怕。

    Because the frames have different width (the drawing needs to recreate steps move) looks like the Imageview resizes the images in the animation. Better to say, if frame1 is bigger then frame2, frame 1 is displayed ok but frame 2 is stretched to be as big as frame1 was. Looks really awful.

    如何制止这种行为有什么建议?谢谢你。

    Any suggestions on how to stop this behavior ? Thank you.

    推荐答案

    该解决方案是很简单,因为在帧图像具有相同的高度,但宽度不同,我只是做了一个透明边框的矩形,并把它在每一帧。在这种情况下,每个帧将具有相同的宽度和animatin将运行应该。

    The solution was quite simple, because images in frames have same height but different width, I simply made a transparent border rectangle and put it over each frame. In this case each frame will have the same width and the animatin will run as supposed to.

    这篇关于Android版的ImageView与AnimationDrawable源代码更改大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆