ShapeableImageView black edge problem

Recently, I encountered a troublesome problem, that is, I am doing picture preview and saving life, and I need to monitor the timing of the picture loading completion, and this picture needs to be displayed by CenterCrop, and it also needs rounded corners. But I don't want to rewrite a custom ImageView myself.
Although I also found that there is a RoundImageView in the current project, but after looking at it, the display mode will be Start, which is not the CenterCrop I want, and I don't want to change it.
And Glide couldn't set the corner because it wanted to monitor it, so it started to look for ducks on the Internet.
Finally, I found that ShapeableImageView can meet my needs. Once I finished using it, there is a black frame behind the rounded corners of this thing. The general instructions did not mention it. After a wave of searching, I found a solution.
Those who say that hardware acceleration and software acceleration are prohibited will not work. In fact, it is enough to set a padding, 0.5 is always ok, anyway, it is not very obvious, so let’s
insert image description here
use it:

implementation 'com.google.android.material:material:1.2.0'

<com.google.android.material.imageview.ShapeableImageView
            android:id="@+id/ivThumbnail"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintDimensionRatio="249:140"
            app:layout_constraintWidth_percent="0.664"
            android:scaleType="centerCrop"
            android:padding="0.5dp"
            app:shapeAppearance="@style/RoadshowCoverStyle"/>

<style name="RoadshowCoverStyle">
        <item name="cornerFamily">rounded</item>
        <item name="cornerSize">8dp</item>
    </style>

still very convenient

Guess you like

Origin blog.csdn.net/fwt336/article/details/127554790