Android的ImageView的:适合宽度宽度、适合、Android、ImageView

由网友(回忆是抓不到的月光)分享简介:我下载的图像,并将其设置为屏幕背景,动态使用的ImageView 。我曾尝试 ScaleType ,将图像缩放。如果图像的高度大于宽度那么大 ScaleTypes fitStart , fitEnd 和 fitCenter 不起作用。 Android的比例放倒照片并适合它的基础上的高度,但我看到一些额外的空白空间的...

我下载的图像,并将其设置为屏幕背景,动态使用的ImageView 。我曾尝试 ScaleType ,将图像缩放。

如果图像的高度大于宽度那么大 ScaleTypes fitStart fitEnd fitCenter 不起作用。 Android的比例放倒照片并适合它的基础上的高度,但我看到一些额外的空白空间的宽度的一部分。

我想根据宽度的照片,以缩减,使其宽度,我不关心,如果有一些额外的空白空间的高度的一部分,或者高度太长它是好的,如果它走出去视图(如果可能的话?)。

ScaleType.XY 缩放照片,适合一切都在的ImageView 并不会在意图像高度/的重量比。

 < ImageView的
                机器人:ID =@ + ID /背景
                机器人:layout_width =match_parent
                机器人:layout_height =match_parent
                机器人:adjustViewBounds =真
                机器人:scaleType =fitStart
            />
 

解决方案

最后我用这个code:

 < ImageView的
                机器人:ID =@ + ID /背景
                机器人:layout_width =match_parent
                机器人:layout_height =match_parent
                机器人:adjustViewBounds =真
                机器人:scaleType =centerCrop
                机器人:SRC =@可绘制/名称
            />
 
android ImageView宽度与高度设定

请确保您设置使用图像的src 而不是背景

I download image and set it as a screen background dynamically using Imageview. I have tried ScaleType, to scale the image.

If image height is larger than width then ScaleTypes fitStart, fitEnd and fitCenter don't work. Android scale down the photo and fit it based on the height, but I see some extra blank space as part of the width.

I want to scale down the photo based on the width so that it fits the width and I don't care if there's some extra blank space as part of the height or if height is too long it is fine if it's going out of the view(if that's possible?).

ScaleType.XY scale the photo and fit everything in the ImageView and doesn't care about image height/weight ratio.

<ImageView 
                android:id="@+id/background"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:adjustViewBounds="true"
                android:scaleType="fitStart"
            />

解决方案

I ended up using this code:

<ImageView 
                android:id="@+id/background"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:adjustViewBounds="true"
                android:scaleType="centerCrop"
                android:src="@drawable/name"
            />

Make sure you set the image using src instead of background.

阅读全文

相关推荐

最新文章