适合ImageView的(和它的SRC)的布局宽度,并使其高度成正比 [英] Fit a ImageView (and its src) to the layout width and make its height proportional
问题描述
你能不能帮我配置我的布局?我没有达到我在寻找什么:
Can you help me to configure my layout? I don't achieve what I'm looking for:
我已经把ImageView的背景为红色说明我想要什么:
I've put the imageview background to red for explain what I want:
图片的宽度比布局宽度。我想图像生长比例保持其宽高比直到到达在第一图像的纵横(Ⅰ改性它用Photoshop手动),但设置宽度=FILL_PARENT的结果是所述第二图像和设置两个宽度和高度,当以 FILL_PARENT的结果是,第三图像
The image's width is smaller than the layout width. I'd like the image grow proportionally keeping its aspect ratio until reach the aspect at the first image (I modified it manually with photoshop) but when setting width="fill_parent" the result is the second image and setting both width and height to "fill_parent" the result is the third image.
我试着用ScaleType结合起来,但没有成功。
I tried to combine with ScaleType with no success
我怎样才能做到第一个选项?谢谢
How can I achieve the first option? Thanks
推荐答案
使用安卓adjustViewBounds = TRUE
ATTR在XML中的的ImageView
Use android:adjustViewBounds=true
attr in xml for ImageView
这个问题是通过扩展ImageView的类在这里解决了。
This question is solved here by extending the ImageView class.
<一个href="http://stackoverflow.com/questions/5554682/android-imageview-adjusting-parents-height-and-fitting-width">Android ImageView的调整家长的高度和宽度装修
我创建了一个样本。这对我的作品。下面是XML布局文件。
I created a sample. It works for me. Here is the xml layout file.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:src="@drawable/hydrangeas"
android:layout_height="wrap_content" android:id="@+id/imageView1"
android:scaleType="centerInside"
android:adjustViewBounds="true"
android:background="@android:color/white"
android:layout_width="wrap_content"/>
</LinearLayout>
它适用于 fitCenter
太。看一看快照。
It works for fitCenter
too. Have a look at the snapshot.
这篇关于适合ImageView的(和它的SRC)的布局宽度,并使其高度成正比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!