- 支持定制化阴影
- 支持随意更改阴影颜色值
- 支持x,y轴阴影偏移
- 可随意更改阴影扩散区域
- 支持阴影圆角属性
- 支持单边或多边不显示阴影
- 支持ShadowLayout背景填充颜色,背景圆角随阴影圆角改变
- 控件支持动态设置shape和selector(项目里再也不用画shape了)
- 修复在xml设置app:clickable="false"时,代码设置为true时,点击事件失效。
- 修改issues#57下的代码规范,非常感谢lydlovezjr同学issues57
因为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 | 组合使用 |
---|---|---|
- 项目build.gradle添加如下
allprojects { repositories { maven { url 'https://jitpack.io' } } }
- app build.gradle添加如下
dependencies { implementation 'com.github.lihangleo2:ShadowLayout:3.0.4' }
<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" />
1、是否展示阴影 app:hl_shadowHidden="true"
- true为隐藏
- 需要带透明度的颜色,如果不带透明度。默认设置透明底16%
- 阴影的扩散区域
- 如下图:右边是对称,不管你怎么偏移,控件所占的区域都是均等的,这也造成了有些同学ui上不好控制。那么你可以加上app:hl_isSym="false"属性。控件区域随着阴影改变,如下图左边样子。
- 也可以理解为左右偏移量
- 也可以理解为上下的偏移量
7、阴影的4边,隐藏哪一边 app:hl_shadowHiddenLeft="true"
- 左边的阴影不可见,其他3边保持不变,其他3边同理
- 统一大小,其中包括了阴影,shape、背景图、stroke边框圆角
- 左上角圆角大小,设置后。左上角会忽略hl_cornerRadius的属性,其他角还是保持hl_cornerRadius的属性。其他3个角同理
- 有2种模式:pressed和selected。和系统shape一样。不难理解
- 这里可以传颜色值,也可以传图片。当为false时的默认背景,也就是手指不点击或者松开后的样式
- 这里可以传颜色值,也可以传图片。当为true时的默认背景,也就是手指点击,按压时的样式
- stroke边宽,stroke的宽度
- 边框颜色值。当为false时的默认边框颜色,也就是手指不点击或者松开后的边框样式
- 边框颜色值。当为true时的默认边框颜色,也就是手指点击,按压时的边框样式
- 设置ShadowLayout是否可以被点击。(这里不是系统的。不用系统的,是因为系统设置setOnclickListener时,会把clickable设置为true);代码设置:mShadowLayout.setClickable(false);
- 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.