CardView+Glide

由appcompat-v7提供的实现卡片式布局的控件CardView
实际上也是个FrameLayout,额外提供了圆角和阴影效果
通过app:cardCornerRadius指定圆角弧度
通过app:elevation指定卡片高度,高度值越大,投影范围越大,投影效果越淡


需要添加依赖

compile 'com.android.support:cardview-v7:24.2.1'

这里用CardView作为RecyclerView单项的最外层布局

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
                                    xmlns:app="http://schemas.android.com/apk/res-auto"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:layout_margin="5dp"
                                    app:cardCornerRadius="4dp">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:id="@+id/item_image"
            android:scaleType="centerCrop"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/item_name"
            android:layout_gravity="center_horizontal"
            android:layout_margin="5dp"
            android:textSize="16sp"/>
    </LinearLayout>

</android.support.v7.widget.CardView>

注意ImageView的scaleType属性,这个属性可以指定图片的缩放模式
centerCrop:让图片保持原有比例充满ImageView,并将超出屏幕的部分裁剪掉
更多ScaleType属性的介绍:http://www.jianshu.com/p/ea8a48768a2e
用Glide加载图片给ImageView加载图片


Glide
图片加载库,可用于加载本地图片,网络图片,gif,本地视频
当图片像素非常高时,不进行压缩直接展示的话,会引起内存溢出
而Glide在内部做了许多复杂的逻辑操作,其中就包括图片压缩
项目主页:https://github.com/bumptech/glide
添加依赖

compile 'com.github.bumptech.glide:glide:3.7.0'

使用

Glide.with(mContext).load(picture.getImageId()).into(holder.pictureImage);

Glide.with(Context|Activity|Fragment)
.load(URL地址|本地路径|资源id)
.into(imageView);

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容