Scale an image up to fill entire ImageView in Android

后端 未结 4 519
天命终不由人
天命终不由人 2021-01-31 07:16

I\'d like to scale an image up to take up the entire size of an ImageView. This is subtly different than using scaleType=fit_center because fit_center will leave b

相关标签:
4条回答
  • 2021-01-31 07:33

    In some cases all you need is

    android:adjustViewBounds="true"
    
    0 讨论(0)
  • 2021-01-31 07:34

    You can use android:scaleType="centerCrop". Keeps the aspect ratio and scales the image just like you want it.

    For more information please go through the below link

    http://developer.android.com/reference/android/widget/ImageView.html#attr_android:scaleType

    0 讨论(0)
  • 2021-01-31 07:51

    Try scaleType attribute for your ImageView. http://developer.android.com/reference/android/widget/ImageView.html#attr_android:scaleType

    0 讨论(0)
  • 2021-01-31 07:51
    imageView.setScaleType(ImageView.ScaleType.FIT_XY);
    

    This worked for me to fit the image inside the whole image view, plus it make sense that it says "ScaleType.FIT_XY" to fit the X and Y axis of the imageView.

    From the xml file it would be:

    android:scaleType="fitXY"
    
    0 讨论(0)
提交回复
热议问题