问题描述
我需要像< IMG WIDTH =100%/>
Android版< ImageView的>
。我的意思是调整宽度到所有可用空间(缩小或放大图像的宽度),并自动改变高度,以保持宽高比。
I need something like<img width="100%" />
for Android <ImageView>
. I mean resize width to all available space (shrink or enlarge width of image) and automatically change height to keep aspect ratio.
喜欢的东西&LT; ImageView的机器人:layout_width =match_parent机器人:layout_height =自动&GT;
使用安卓scaleType =fitCenter
做的形象是我想要的,但只有形象,不改变视图本身的高度。当我设置展位尺寸match_parent我会得到我想要的,但是只有当我在屏幕上只有一个映像。但我需要在图像的一些文本。
Useandroid:scaleType="fitCenter"
do with image what I want, but only with image, doesn't change height of View itself. When I set booth dimensions to match_parent I will get what I want, but only if I have only one image on the screen. But I need some texts under image.
它的唯一的方式创建的ImageView的孩子呢?例如机器人:adjustViewBounds =真正的
简化版,为我做任何事
It's only way create child of ImageView?For exampleandroid:adjustViewBounds="true"
does't do anything for me.
推荐答案
我发现在哪里的问题。默认实现ImageView的不能放大图片。如果图像大于屏幕宽度的android:adjustViewBounds =真正的正常工作,并调整高度,以保持图像的宽高比。但是,如果图像是较小的屏幕宽度也没有高档的了。
I found where is problem. Default implementation of ImageView can't enlarge image. If image is bigger than screen width android:adjustViewBounds="true" works correctly and adjust height to keep aspect ratio of image. But if image is smaller that screen width it don't upscale it.
这是造成本code
if (newHeight <= heightSize) {
heightSize = newHeight;
}
在ImageView的类(上线688,API 10)
in ImageView class (on line 688, API 10)
我在ImageView的,允许放大图片以适应宽度特别的孩子。
I made special child of ImageView which allow enlarge image to fit width.
下面是: https://gist.github.com/tprochazka/5486822
这篇关于ImageView的一个尺寸,以适应自由空间和第二评估,以保持宽高比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!