支持定制化阴影:
1. 随意修改阴影颜色值
2. 阴影圆角:可统一设置圆角,也可对某几个角单独设置
3. x,y轴阴影偏移
4. 随意修改阴影扩散程度
5. 隐藏阴影:隐藏某边或多边阴影,或完全隐藏
不止于阴影;系统shape功能:项目中shape、selector、ripple统统拥有。解放你的双手,清空项目drawable文件夹
1. shape样式:pressed(按钮点击)、selected(按钮选择)、ripple(点击水波纹)
2. 背景色设置
3. stroke边框设置
4. 渐变色背景色值
5. 按钮是否可被点击
- shapeMode新增了ripple(点击水波纹样式),具体会在README中说明
- ShadowLayout,新增了渐变色,这也是issues大量出现的需求,感谢大家的支持
因为3.0修改了大量api及规范命名,如不方便转移还在使用2.0的。可查看2.0文档ShadowLayout 2.1.8
基础功能展示 | 各属性展示 | 随意更改颜色 |
---|---|---|
2.1.6新增shape,selector功能 | 2.1.7isSym属性对比 | 2.1.8单独更改某圆角大小 |
---|---|---|
stroke边框及点击 | shape及图片selector | 组合使用 |
---|---|---|
stroke边框及点击 |
---|
- 项目build.gradle添加如下
allprojects { repositories { maven { url 'https://jitpack.io' } } }
- app build.gradle添加如下
dependencies { implementation 'com.github.lihangleo2:ShadowLayout:3.1.0' }
<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>
<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>
<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>
<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" />
<com.lihang.ShadowLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:hl_cornerRadius="18dp"
app:hl_startColor="#ff0000"
app:hl_endColor="#0000ff"
>
<TextView
android:layout_width="160dp"
android:layout_height="40dp"
android:gravity="center"
android:text="渐变色"
android:textColor="#fff" />
</com.lihang.ShadowLayout>
<com.lihang.ShadowLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:hl_cornerRadius="18dp"
app:hl_shadowColor="#2a000000"
app:hl_shadowLimit="7dp"
app:hl_layoutBackground="#fff"
app:hl_layoutBackground_true="#ff0000"
app:hl_shapeMode="ripple"
>
<TextView
android:layout_width="160dp"
android:layout_height="40dp"
android:gravity="center"
android:text="水波纹"
/>
</com.lihang.ShadowLayout>
name | format | description |
---|---|---|
hl_cornerRadius | dimension | 包括阴影圆角、shape圆角(dp) |
hl_cornerRadius_leftTop | dimension | 左上圆角,其他角还是hl_cornerRadius值;同理其他3角(dp) |
name | format | description |
---|---|---|
hl_shapeMode | enum | 有3种模式:pressed和selected。和系统shape一样,以及ripple点击水波纹 |
hl_layoutBackground | reference/color | 背景色,为false时展示:可以是颜色值,图片以及系统shape样式 |
hl_layoutBackground_true | reference/color | 背景色,为true时展示:可以是颜色值,图片以及系统shape样式 |
name | format | description |
---|---|---|
hl_strokeWith | dimension | stroke边框线宽度 |
hl_strokeColor | color | 边框颜色值,为false展示 |
hl_strokeColor_true | color | 边框颜色值,为true展示 |
name | format | description |
---|---|---|
hl_startColor | color | 渐变起始颜色(设置渐变色后,hl_layoutBackground属性将无效) |
hl_centerColor | color | 渐变中间颜色(可不填) |
hl_endColor | color | 渐变的终止颜色 |
hl_angle | integer | 渐变角度(默认0) |
name | format | description |
---|---|---|
clickable | boolean | 设置ShadowLayout是否可以被点击;代码设置:mShadowLayout.setClickable(false);(默认true) |
hl_layoutBackground_clickFalse | reference/color | Clickable为false时,要展示的图片或颜色。(此属性应当在app:hl_shapeMode="pressed"时生效) |
Android工作多年了,一直向往大厂。在前进的道路上是孤独的。如果你在学习的路上也感觉孤独,请和我一起。让我们在学习道路上少些孤独
- 关于我的经历
- QQ群: 209010674 (点击图标,可以直接加入)
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.