利用CardView,使Picasso加载圆角图片

    xiaoxiao2021-03-25  136

    一、去除CardView的阴影

    参考博客:http://blog.csdn.net/aheeyiqi/article/details/51064454

    正如CardView的阴影属性,绝大部分时候都是需要的,但是有时候纯粹当作ListView使用则不希望显示阴影,该怎么办呢?

    1、首先,设置阴影属性

    app:cardElevation="0px"    //阴影大小

    app:cardMaxElevation="2px"   //最大阴影大小,该值最小2px

    app:cardUseCompatPadding="false"   //不显示阴影

    2、设置了以上属性仍然可能会有阴影,再设置

    app:contentPaddingBottom="-20dp"    //-20dp随便,为了保险起见取的20

    app:contentPaddingTop="-20dp"

    3、到此如果还是有阴影,那么就在Adapter的nBindViewHolder()方法中,设置CardView的背景色, 就可以完全解决去除阴影问题了

    holder.content.setBackgroundColor(0xFFFFFFFF);   //content是CardView的布局

    实现这3个步骤就可以完全解决去除CardView阴影这一问题了,经测试在android4.4 5.0都通过。

    二、布局文件

    <android.support.v7.widget.CardView android:layout_width="match_parent" android:layout_height="134dp" app:cardCornerRadius="10dp" app:cardElevation="0px" app:cardMaxElevation="2dp" app:cardUseCompatPadding="false"> <ImageView android:id="@+id/photo_album_detail_item_photo" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop"/> </android.support.v7.widget.CardView>  

    三、Picasso加载图片

    Picasso.with(context).load(data!![position].photo).into(R.id.photo_album_detail_item_photo)

    转载请注明原文地址: https://ju.6miu.com/read-2470.html

    最新回复(0)