你如何正确地缩放ImageView

时间:2013-06-19 20:39:08

标签: android view imageview scaling

ALL,

我正在Android上开发一个应用程序,我需要从Web加载图像并将其与ListView一起呈现给用户以及其他一些东西。所以我制作了2个XML文件(用于行和整个显示),编写代码来获取图像并编写适当的适配器。

这就是我所拥有的:

product_line.xml:

<ImageView
    android:id="@+id/product_picture"
    android:contentDescription="@string/product_picture"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
/>
<TextView
    android:id="@+id/product_name"
    android:layout_toRightOf="@id/product_picture"
    android:layout_alignParentTop="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
/>
<TextView
    android:id="@+id/product_price"
    android:layout_below="@id/product_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
/>
<Button
    android:id="@+id/add_to_cart"
    android:layout_below="@id/product_price"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/add_to_cart"
/>

不幸的是,在运行代码时,我发现视图比下载的图像大得多,因此尽管采用了“wrap_content”设置,但仍需要很多空间。

是否有可能以某种方式设置视图尺寸以正确显示所有内容?

谢谢。

[编辑] 我发现了这个:http://argillander.wordpress.com/2011/11/24/scale-image-into-imageview-then-resize-imageview-to-match-the-image/,但不幸的是它没有任何区别。 [/编辑]

1 个答案:

答案 0 :(得分:1)

要缩小图片视图,请使用:

android:adjustViewBounds="true"
android:maxWidth="32dp" <!--set the width you wish to be -->
相关问题