简体   繁体   中英

Remove whitespace from image in Android Studio

在此处输入图片说明

As one can see in the above image there is a lot of white space around the small image in this ImageView layout. How do I remove the white space and make the image view the same size as the actual image it is displaying? If I make the ImageView smaller, it makes the view smaller but still has white space around the image itself. How do I remove it?

在此处输入图片说明

Thanks.

在图像视图中设置 XML 属性 adjustViewBounds="true"

You simply need to do

 android:layout_width="wrap_content"
 android:layout_height="wrap_content"

in image view.

In addition to that, u can do below things for good practices

you can use ImageView.ScaleType(FIT_XY) but this will change ration of your image and x,y axis expands independently fill your image view

u need to add android:scaleType="fitXY" in xml file image view for it.

you can use ImageView.ScaleType(FIT_CENTER) it will keep ration and expan x,y until one fill your image view

u need to add android:scaleType="fitCenter" in xml file image view for it.

you can find all of the options by navigating this https://developer.android.com/reference/android/widget/ImageView.ScaleType

I've researched some fixes and none of them worked. What did work was changing from a mipmap to a drawable image. I'm getting other errors, but at least the original problem has been fixed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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