问题描述
在Android的,我定义的的ImageView
的 layout_width
是 FILL_PARENT
(它接受了电话的全宽)。
In Android, I defined an ImageView
's layout_width
to be fill_parent
(which takes up the full width of the phone).
如果我投入到的ImageView
图像大于 layout_width
,Android将它的规模,对不对?但怎么样的高度?当Android的缩放图像,将其保持纵横比?
If the image I put to ImageView
is bigger than the layout_width
, Android will scale it, right? But what about the height? When Android scales the image, will it keep the aspect ratio?
我发现是,有在顶部和底部的一些空白的的ImageView
当Android的缩放图像是大于 ImageView的
。真的吗?如果是的话,我怎么能消除空白?
What I find out is that there is some white space at the top and bottom of the ImageView
when Android scales an image which is bigger than the ImageView
. Is that true? If yes, how can I eliminate that white space?
推荐答案
1)是的,默认情况下,Android将会扩展您的形象,以适应ImageView的,保持纵横比。但是,请确保您使用的是 Android上的图像设置为ImageView的:SRC =...
,而不是安卓背景=。 ..
。 SRC =
使缩放图像保持高宽比,但背景=
使其规模的和扭曲图像,使其完全适合于ImageView的大小。 (可以使用一个背景,并在同一时间,虽然一源,它可以是对于像显示绕主图像的帧,只使用一个ImageView的是有用的。)
1) Yes, by default Android will scale your image down to fit the ImageView, maintaining the aspect ratio. However, make sure you're setting the image to the ImageView using android:src="..."
rather than android:background="..."
. src=
makes it scale the image maintaining aspect ratio, but background=
makes it scale and distort the image to make it fit exactly to the size of the ImageView. (You can use a background and a source at the same time though, which can be useful for things like displaying a frame around the main image, using just one ImageView.)
2)你也应该看到安卓adjustViewBounds
使ImageView的调整自身以适应重新缩放图像。例如,如果您有什么通常是一个正方形的ImageView矩形图像,adjustViewBounds = true,将使其调整ImageView的是矩形为好。然后,这会影响其他是如何看待的布局方式围绕ImageView的。
2) You should also see android:adjustViewBounds
to make the ImageView resize itself to fit the rescaled image. For example, if you have a rectangular image in what would normally be a square ImageView, adjustViewBounds=true will make it resize the ImageView to be rectangular as well. This then affects how other Views are laid out around the ImageView.
然后为Samuh写的,你可以改变它默认使用 Android的尺度图像的方式:scaleType
参数。顺便说一句,最简单的方法来发现它是如何工作也只会被自己实验一下!不过,别忘了看看模拟器本身(或实际的电话)布局为preVIEW在Eclipse中通常是错误的。
Then as Samuh wrote, you can change the way it default scales images using the android:scaleType
parameter. By the way, the easiest way to discover how this works would simply have been to experiment a bit yourself! Just remember to look at the layouts in the emulator itself (or an actual phone) as the preview in Eclipse is usually wrong.
这篇关于如何缩放图像中的ImageView保持宽高比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!