How to create an ImageView that fills the parent height and displays an Image as big as possible?

前端 未结 4 864
情话喂你
情话喂你 2021-02-03 21:41

I have an ImageView that is defined in the following way:

 

        
相关标签:
4条回答
  • 2021-02-03 22:06

    Basically the answer here is that there is no predefined value for what you are trying to achieve. The solution is to create a Matrix that fits to your needs and call setImageMatrix(matrix) on your ImageView.

    0 讨论(0)
  • 2021-02-03 22:19

    simply do it in xml like

    android:scaleType="fitXY"
    
    0 讨论(0)
  • 2021-02-03 22:24

    You can change scale type to fitXY via call to

    imageView.setScaleType(ScaleType.FIT_XY);
    
    0 讨论(0)
  • 2021-02-03 22:31

    If I'm understanding you correctly, what you need to use is the centerCrop scaleType. fitStart scales the image proportionally, but neither the width nor height will exceed the size of the view, and the image will, as you said, have a top|left gravity.

    Using centerCrop scales the image proportionally, but causes the shortest edge of the image to match the size of the view, and if there is additional data on the long side that does not fit, it is simply cropped off. The gravity is, of course, center. The below worked for me:

    <ImageView
            android:src="@drawable/image_placeholder"
            android:id="@+id/cover_view"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:scaleType="centerCrop"
    />
    
    0 讨论(0)
提交回复
热议问题