ShapeableImageView黑边问题

最近碰到一个麻烦的问题,就是我在做图片预览和保存的生活,需要监听到图片加载完成的时机,而这个图片需需要CenterCrop显示,同时还需要圆角。但是我又不想自己再重新写个自定义的ImageView。
虽然我也发现了目前的项目里有个RoundImageView,但是看了下会导致显示方式为 Start 不是我要的 CenterCrop ,也不想去改它了。
而Glide由于要给来做监听,也没法设置corner了,就开始在网上找鸭找。
最后发现了ShapeableImageView可以满足我的需求,一用完蛋了,这玩意居然圆角后有黑框,一般的使用说明都没提到,一波搜索后发现了解决办法。
那些说禁止硬件加速和软件加速的都不行。实际上需要设置一个padding就可以了,0.5总可以了吧,反正也不太看的出来,就这样吧
ShapeableImageView黑边问题_第1张图片
使用方法:

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>

感觉还是很方便的

你可能感兴趣的:(安卓开发,android)