在整个屏幕上旋转图像
我似乎无法在整个屏幕上正确旋转图像。问题是当图像旋转时,您可以在某些区域看到背景。我希望图像在旋转时也能填满屏幕。这是布局。我尝试过不同的比例类型但没有成功。
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop" />
</LinearLayout>
这是我正在使用的代码。
image = (ImageView) findViewById(R.id.image);
image.setBackgroundResource(R.drawable.back_big);
rot = AnimationUtils.loadAnimation(this, R.anim.rotation);
image.startAnimation(rot);
我在 onResume
中启动动画。正如我所说,图像会旋转,但旋转时会有背景区域。我尝试过使用比屏幕大得多的图像,但它仍然达不到我想要的效果。我不在乎图像的外部区域不可见。我只是想让旋转填满屏幕。我猜 ImageView 最初设置了它的宽度和高度,然后当它旋转时,它使用这些尺寸。有更好的方法吗?
I can't seem to rotate properly an image on the entire screen. The problem is that when the image rotates, you can see the background in some areas. I want the image to fill the screen also when it rotates. Here is the layout. I've tried different scale types without success.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop" />
</LinearLayout>
And here is the code that I am using.
image = (ImageView) findViewById(R.id.image);
image.setBackgroundResource(R.drawable.back_big);
rot = AnimationUtils.loadAnimation(this, R.anim.rotation);
image.startAnimation(rot);
I start the animation in onResume
. As I said, the image rotates but there are background areas when it does rotate. I've tried using images much bigger than the screen but still it doesn't do what I want. I don't care that outer regions of the image are not visible. I just want the rotation to fill the screen. I guess ImageView
sets its width and height initially and then, when it rotates, it uses those dimensions. Is there a better way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您将 ImageView 的scaleType 设置为“centerCrop”。不幸的是,没有关于不同scaleTypes的确切含义的良好文档,但名称意味着图像位于屏幕中央并裁剪为ImageView的确切大小。因此,当您开始旋转时,您将看到背景区域。
尝试将scaleType更改为“center”。
You are setting the scaleType of your ImageView to "centerCrop". Unfortunatly there isn't good documentation on the exact meaning of the different scaleTypes, but the name implies that the image is centered on the screen and cropped to the exact size of the ImageView. Thus, when you begin to rotate you will see background areas.
Try chaging the scaleType to just "center".
经过更多地研究问题后,我认为不可能实现我想要的目标。如果可以的话,那就太复杂了,不值得。
After looking more at the problem, I don't think it's possible to achieve what I want. If it is possible, then it is too complicated and it's not worth it.
你可以 :
You can :