Android的ImageView的:适合宽度 [英] Android ImageView: Fit Width

查看:206
本文介绍了Android的ImageView的:适合宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下载的图像,并将其设置为屏幕背景,动态使用的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 =@可绘制/名称
            />
 

请确保您设置使用图像的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.

这篇关于Android的ImageView的:适合宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆