zpzgone / ShadowLayout

可定制化阴影的万能阴影布局ShadowLayout 3.0 震撼上线。效果赶超CardView。阴影支持x,y轴偏移,支持阴影扩散程度,支持阴影圆角,支持单边或多边不显示阴影;控件支持动态设置shape和selector(项目里再也不用画shape了);支持随意更改颜色值,支持随意更改颜色值,支持随意更改颜色值。重要的事情说三遍

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

万能阴影布局,定制化你要的阴影。 ShadowLayout 3.0来袭(需要阴影地方,被它嵌套即可享受阴影,阴影可定制化,效果赶超CardView)

  • 支持定制化阴影
  • 支持随意更改阴影颜色值
  • 支持x,y轴阴影偏移
  • 可随意更改阴影扩散区域
  • 支持阴影圆角属性
  • 支持单边或多边不显示阴影
  • 支持ShadowLayout背景填充颜色,背景圆角随阴影圆角改变
  • 控件支持动态设置shape和selector(项目里再也不用画shape了)

3.0.1更新功能及ShadowLayout成长历程

  • 完善shape功能,解放你的drawable文件。包括有:图片selector、shape selector、stroke selector
  • ShadowLayout提供了背景圆角方案
  • 修改了部分单词拼写错误,及大量属性命名。更规范
  • 其中也加上了设置Clickable ="false"的样式。
  • 修改了目前已知bug,及修改和完善了不规则圆角的阴影方案 Shadow成长历程

注意

因为3.0修改了大量api及规范命名,如不方便转移还在使用2.0的。可查看2.0文档ShadowLayout 2.1.8

效果展示(截图分辨率模糊,真机运行效果赶超CardView)

基础功能展示 各属性展示 随意更改颜色

2.0功能更新

2.1.6新增shape,selector功能 2.1.7isSym属性对比 2.1.8单独更改某圆角大小
Sample

3.0.1版本来袭

stroke边框及点击 shape及图片selector 组合使用
Sample

扫描二维体验效果(下载密码是:123456)


添加依赖

  • 项目build.gradle添加如下
    allprojects {
     	repositories {
     		maven { url 'https://jitpack.io' }
     	}
     }
  • app build.gradle添加如下
    dependencies {
            implementation 'com.github.lihangleo2:ShadowLayout:3.0.1'
    }

基本使用

一、阴影的简单使用

            <com.lihang.ShadowLayout
                android:id="@+id/mShadowLayout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                app:hl_cornerRadius="10dp"
                app:hl_shadowColor="#2a000000"
                app:hl_shadowLimit="5dp"
                >

                <TextView
                    android:id="@+id/txt_test"
                    android:layout_width="wrap_content"
                    android:layout_height="36dp"
                    android:gravity="center"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:text="圆角"
                    android:textColor="#000" />
            </com.lihang.ShadowLayout>

二、stroke边框的简单使用

            <com.lihang.ShadowLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                app:hl_cornerRadius="10dp"
                app:hl_strokeColor="#000">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="36dp"
                    android:gravity="center"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:text="圆角边框"
                    android:textColor="#000" />
            </com.lihang.ShadowLayout>

三、shape selector的简单使用

            <com.lihang.ShadowLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="10dp"
                app:hl_cornerRadius="30dp"
                app:hl_cornerRadius_leftTop="0dp"
                app:hl_layoutBackground="#F76C6C"
                app:hl_layoutBackground_true="#89F76C6C"
                app:hl_shapeMode="pressed">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="36dp"
                    android:gravity="center"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:text="selector的pressed用法,请点击"
                    android:textColor="#fff" />
            </com.lihang.ShadowLayout>

三、图片 selector的简单使用

    <com.lihang.ShadowLayout
        android:id="@+id/ShadowLayout_shape"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="10dp"
        app:hl_cornerRadius="18dp"
        app:hl_cornerRadius_rightTop="0dp"
        app:hl_layoutBackground="@mipmap/test_background_false"
        app:hl_layoutBackground_true="@mipmap/test_background_true">


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="36dp"
            android:gravity="center"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:text="图片selector"
            android:textColor="#fff" />

    </com.lihang.ShadowLayout>

如果你觉得麻烦,你还可以这样

            <com.lihang.ShadowLayout
                android:id="@+id/ShadowLayout_image"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="10dp"
                app:hl_layoutBackground="@mipmap/game_6_right"
                app:hl_layoutBackground_true="@mipmap/game_6_wrong"
                app:hl_shapeMode="pressed" />

自定义属性

一、关于阴影

1、是否展示阴影 app:hl_shadowHidden="true"

  • true为隐藏

2、阴影的颜色 app:hl_shadowColor="#29000000"

  • 需要带透明度的颜色,如果不带透明度。默认设置透明底16%

3、阴影扩散程度 app:hl_shadowLimit="5dp"

  • 阴影的扩散区域

4、 控件区域是否对称,默认是对称。不对称的话,那么控件区域随着阴影区域走:app:hl_shadowSymmetry="false"

  • 如下图:右边是对称,不管你怎么偏移,控件所占的区域都是均等的,这也造成了有些同学ui上不好控制。那么你可以加上app:hl_isSym="false"属性。控件区域随着阴影改变,如下图左边样子。

Sample

5、x轴的偏移量 app:hl_shadowOffsetX="0dp"

  • 也可以理解为左右偏移量

6、y轴的偏移量 app:hl_shadowOffsetY="0dp"

  • 也可以理解为上下的偏移量

7、阴影的4边,隐藏哪一边 app:hl_shadowHiddenLeft="true"

  • 左边的阴影不可见,其他3边保持不变,其他3边同理

二、关于圆角

8、圆角 app:hl_cornerRadius="30dp"

  • 统一大小,其中包括了阴影,shape、背景图、stroke边框圆角

9、某个角的圆角 app:hl_cornerRadius_leftTop="0dp"

  • 左上角圆角大小,设置后。左上角会忽略hl_cornerRadius的属性,其他角还是保持hl_cornerRadius的属性。其他3个角同理

三、关于shape及selector

10、控件按压方式 app:hl_shapeMode="pressed"

  • 有2种模式:pressed和selected。和系统shape一样。不难理解

11、控件默认背景:false。 app:hl_layoutBackground="#fff"

  • 这里可以传颜色值,也可以传图片。当为false时的默认背景,也就是手指不点击或者松开后的样式

12、控件默认背景:true。 app:hl_layoutBackground_true="#ff0000"

  • 这里可以传颜色值,也可以传图片。当为true时的默认背景,也就是手指点击,按压时的样式

四、关于stroke边框

13、stroke边框线宽度 app:hl_strokeWith="1dp"

  • stroke边宽,stroke的宽度

14、边框默认颜色:false。 app:hl_strokeColor="#fff"

  • 边框颜色值。当为false时的默认边框颜色,也就是手指不点击或者松开后的边框样式

15、边框默认颜色:true。 app:hl_strokeColor_true="#ff0000"

  • 边框颜色值。当为true时的默认边框颜色,也就是手指点击,按压时的边框样式

16、类似于系统的Clickable app:hl_layoutBackgroundClickableFalse="false"

  • Clickable为false时,要展示的图片或颜色。注意,此属性应当在app:hl_shapeMode="pressed"时生效。其他模式下只是不能点击,并不会展示此图

关于作者。

Android工作多年了,一直向往大厂。在前进的道路上是孤独的。如果你在学习的路上也感觉孤独,请和我一起。让我们在学习道路上少些孤独


Licenses

MIT License

Copyright (c) 2019 leo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

About

可定制化阴影的万能阴影布局ShadowLayout 3.0 震撼上线。效果赶超CardView。阴影支持x,y轴偏移,支持阴影扩散程度,支持阴影圆角,支持单边或多边不显示阴影;控件支持动态设置shape和selector(项目里再也不用画shape了);支持随意更改颜色值,支持随意更改颜色值,支持随意更改颜色值。重要的事情说三遍

License:MIT License


Languages

Language:Java 100.0%