我在imageview中运行的动画拒绝保持图像帧的纵横比。在所以下面的答案是相当有价值的信息,但似乎并没有为我工作: How to scale an Image in ImageView to keep the aspect ratioAndroid:如何在动画中保持纵横比
下面是代码:
private void startAnimation(){
mImageView.setAdjustViewBounds(true);
mImageView.setScaleType(ScaleType.CENTER);
mImageView.setBackgroundResource(R.anim.my_animation);
AnimationDrawable frameAnimation = (AnimationDrawable) mImageView.getBackground();
// Start the animation (looped playback by default).
frameAnimation.start();
}
R.anim.my_animation只是一个动画列表:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/selected"
android:oneshot="false">
<item
android:drawable="@drawable/photo_1"
android:duration="100" />
<item
android:drawable="@drawable/photo__2"
android:duration="100" />
... and so on...
</animation-list>
根据您引用的问题,该解决方案使用了XML布局。发布您的XML布局,以便我们可以验证您是否正确定义了参数。 – user432209 2011-05-16 16:56:21
@ user432209:+1。你帮我弄清楚我的错误。我已经将imageview的高度和宽度设置为绝对值(因为它显示了除动画之外的其他东西)。删除可以解决问题。谢谢! – OceanBlue 2011-05-16 18:37:52