How to auto center crop ImageView Android?

前端 未结 4 816
感动是毒
感动是毒 2020-12-13 05:50

I made a listView images. My goal that each item of my listView have the same height of 100dp. I encounter a problem that my imageView is resized automatically, but does not

相关标签:
4条回答
  • 2020-12-13 06:10

    I am not sure if I understood correctly. It must be either of the two, that you want, I guess.

    In your image view set the attribute

    android:scaleType="fitXY"
    

    to fit the ImageView completely.

    You can choose

    android:scaleType="centerCrop"
    

    to crop Center.

    0 讨论(0)
  • 2020-12-13 06:10

    Are you aware of the cropping options on ImageView?

    http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

    You will just apply these as an attribute in your XML:

    like:

    android:scaleType="centerCrop"  
    
    0 讨论(0)
  • 2020-12-13 06:25

    in java: imageView.setScaleType(ScaleType.FIT_XY);

    0 讨论(0)
  • 2020-12-13 06:28

    i know it's late but maybe it would be helpful for someone coming on this question page by using android:scaleType="centerCrop" image is centered but it is cropped from all sides so it would be better to use this property instead that is fitCenter and with this use another property too to maintain the aspect ratio

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