2018-08-02 Android中实现阴影和图片圆角效果

Android中实现阴影和图片圆角效果

这里要讲的是两个github上两个开源的轮子

圆角效果的依赖

implementation 'com.makeramen:roundedimageview:2.3.0'

阴影效果的依赖

implementation 'com.github.dmytrodanylyk.shadow-layout:library:1.0.3'

圆角依赖使用时,只需要在布局中设置

<com.makeramen.roundedimageview.RoundedImageView
android:id="@+id/incom_center_banner_iv_base"
android:layout_width="match_parent"
android:scaleType="centerCrop"
app:riv_corner_radius="15px"
app:riv_corner_radius_top_left="@dimen/x10"
app:riv_corner_radius_top_right="@dimen/x10"
app:riv_corner_radius_bottom_right="@dimen/x10"
app:riv_corner_radius_bottom_left="@dimen/x10"
app:riv_mutate_background="true"
app:riv_tile_mode="repeat"
android:layout_height="@dimen/x280" />

根据下面四个值,便可以设置每个角的度数

app:riv_corner_radius_top_left="@dimen/x10"
app:riv_corner_radius_top_right="@dimen/x10"
app:riv_corner_radius_bottom_right="@dimen/x10"
app:riv_corner_radius_bottom_left="@dimen/x10"

阴影效果的依赖使用时,也只需要在布局中设置即可

<com.dd.ShadowLayout
    android:layout_width="match_parent"
    //阴影颜色
    app:sl_shadowColor="#15afafaf"
    android:layout_gravity="center"
    app:sl_shadowRadius="@dimen/x6"
    //阴影距离
    app:sl_cornerRadius="8px"
    //正值,往下偏移,负值,往上偏移
    app:sl_dy="@dimen/x10"
    //正值,往右偏移,负值,往左偏移
    app:sl_dx="@dimen/x10"
    android:layout_height="wrap_content">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_gravity="center_horizontal"
        //如果阴影没有显示出来,给被ShadowLayout包裹的控件设置margin值
        android:layout_marginRight="@dimen/x10"
        android:layout_marginLeft="@dimen/x10"
        android:layout_marginTop="@dimen/x8"
        android:layout_marginBottom="@dimen/x8"
        android:background="@drawable/bg_new_re_index"
        android:layout_height="wrap_content">
        <com.makeramen.roundedimageview.RoundedImageView
            android:id="@+id/iv_pager"
            android:layout_width="match_parent"
            android:scaleType="centerCrop"
            app:riv_corner_radius="15px"
            app:riv_mutate_background="true"
            app:riv_tile_mode="repeat"
            android:layout_height="match_parent" />
    </RelativeLayout>
</com.dd.ShadowLayout>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,925评论 25 709
  • 1、通过CocoaPods安装项目名称项目信息 AFNetworking网络请求组件 FMDB本地数据库组件 SD...
    阳明AI阅读 16,023评论 3 119
  • 熬夜,晚睡,明明很困,可就是不愿意关上手机,不愿闭上眼睛。明明已经没有事情,但是非要绞尽脑汁想出一件要做的事来。为...
    雪姨_阅读 364评论 0 0
  • 打算记录日常小事,很温馨的小事。 今天上午,我告诉他我在背英语单词文科写作业。 他说那么认真,外加了一个亲亲的表情...
    沙扬娜拉_阅读 250评论 0 0
  • 个人主页,可用于展示自己,亦可作为博客和其他网络社区的连接点。接下来我将来给大家展示如何用1块钱快速搭建自己的个人...
    cbits阅读 355评论 0 0