我在 imageview 中运行的动画拒绝保持图像帧的纵横比。SO中的以下答案非常有用,但似乎对我不起作用: How to scale an Image in ImageView to keep the aspect ratio
这是代码:
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>