简体   繁体   English

将ImageView中的图像缩放到完整大小

[英]Scaling image in ImageView to full size

I have an ImageView and an extern image which gets load into the ImageView on start. 我有一个ImageView和一个extern图像,可以在启动时加载到ImageView中。 The problem is: the image doesn't have the height of the device. 问题是:图像没有设备的高度。 The width is correctly full size. 宽度是正确的全尺寸。 How can I achieve the image to be as high as the deviceheight so that it is fullscreen? 如何使图像达到设备高度,使其全屏?

If you don't care about aspect ratio , use 如果您不关心纵横比 ,请使用

android:adjustViewBounds="false" 
android:scaleType="fitXY"

Or if programatically... 或者如果以编程方式......

ImageView imageView = (ImageView)v.findViewById(R.id.fullImage);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);

Hope this helps... 希望这可以帮助...

Try this 尝试这个

Display mDisplay= activity.getWindowManager().getDefaultDisplay();
int width= mDisplay.getWidth();
int Height= mDisplay.getHeight();

You can get the device height and set the imageview's height programmatically. 您可以获取设备高度并以编程方式设置imageview的高度。

imageView.getLayoutParams().height = Height;

First set width and height of your imageview to match_parent 首先将imageview的宽度和高度设置为match_parent

There are few scale type provided by imageview widget in android : android中的imageview小部件提供的缩放类型很少:

out of which, I use centerCrop very often because it maintains the aspect ratio but you can find what suits you better. 其中,我经常使用centerCrop,因为它保持了宽高比,但你可以找到更适合你的东西。

android:scaleType="centerCrop"

also don't forget to write this line in your xml : 也不要忘记在你的xml中写这行:

android:adjustViewBounds="false"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM