安卓TextView文字悬浮阴影效果实现
来源:互联网 发布:学校机房监控软件 编辑:程序博客网 时间:2024/05/16 12:14
在Textview上实现悬浮阴影效果只需要设置Textview的一下属性即可
根据值的不同效果也会出现差异
直接上图吧
根据值的不同效果也会出现差异
不要刚开始测试的时候注意先改一下背景颜色,不然可能看不出效果
属性如下
1. android:shadowColor:阴影的颜色
2. android:shadowDx:水平方向上的偏移量
3. android:shadowDy:垂直方向上的偏移量
4. android:shadowRadius:阴影的范围(可以直接理解为阴影的模糊程度,值越大越模糊,>=0&&<=25)
android:shadowDx和android:shadowDy一起控制阴影出现的位置
首先我们定义几个颜色,方便后面用到
<resources> <color name="colorPrimary">#3F51B5</color> <color name="colorPrimaryDark">#303F9F</color> <color name="colorAccent">#FF4081</color> <color name="White">#FFF</color> <color name="Black">#000</color> <color name="Grey">#7F7F7F</color> <color name="DarkGrey">#4F4F4F</color> <color name="Green">#0F0</color> <color name="TransparentGrey">#7F000000</color> </resources>
直接上图吧
代码如下
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:showDividers="middle" android:padding="@dimen/activity_vertical_margin" android:background="@color/White" tools:context="com.tyu.mytestapplication.MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="18sp" android:textColor="@color/Black" android:shadowColor="@color/TransparentGrey" android:shadowDx="3" android:shadowDy="3" android:shadowRadius="0" android:text="光源在左上角,偏移量3,阴影0,无效果"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="18sp" android:textColor="@color/Black" android:shadowColor="@color/TransparentGrey" android:shadowDx="3" android:shadowDy="3" android:shadowRadius="5" android:text="光源在左上角,偏移量3,阴影5"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="18sp" android:textColor="@color/Black" android:shadowColor="@color/TransparentGrey" android:shadowDx="10" android:shadowDy="10" android:shadowRadius="5" android:text="光源在左上角,偏移量10,阴影5"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="18sp" android:textColor="@color/Black" android:shadowColor="@color/TransparentGrey" android:shadowDx="15" android:shadowDy="15" android:shadowRadius="5" android:text="光源在左上角,偏移量15,阴影5"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="18sp" android:textColor="@color/Black" android:shadowColor="@color/TransparentGrey" android:shadowDx="7" android:shadowDy="7" android:shadowRadius="10" android:text="光源在左上角,偏移量7,阴影10"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="18sp" android:textColor="@color/Black" android:shadowColor="@color/TransparentGrey" android:shadowDx="15" android:shadowDy="15" android:shadowRadius="10" android:text="光源在左上角,偏移量15,阴影10"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="18sp" android:textColor="@color/Black" android:shadowColor="@color/TransparentGrey" android:shadowDx="10" android:shadowDy="10" android:shadowRadius="15" android:text="光源在左上角,偏移量10,阴影15"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="18sp" android:textColor="@color/Black" android:shadowColor="@color/TransparentGrey" android:shadowDx="10" android:shadowDy="-10" android:shadowRadius="5" android:text="光源在左下角,偏移量10,阴影5"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="18sp" android:textColor="@color/Black" android:shadowColor="@color/TransparentGrey" android:shadowDx="10" android:shadowDy="-10" android:shadowRadius="25" android:text="光源在左下角,偏移量10,阴影25"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="18sp" android:textColor="@color/Black" android:shadowColor="@color/colorAccent" android:shadowDx="0" android:shadowDy="0" android:shadowRadius="15" android:text="长毛的文字,偏移量为0,阴影15"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="18sp" android:textColor="@color/Black" android:shadowColor="@color/colorAccent" android:shadowDx="0" android:shadowDy="0" android:shadowRadius="25" android:text="长毛的文字,偏移量为0,阴影25"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="18sp" android:textColor="@color/White" android:shadowColor="@color/colorAccent" android:shadowDx="0" android:shadowDy="0" android:shadowRadius="15" android:text="空心字效果,偏移量为0,阴影15"/></LinearLayout>
阅读全文
0 0
- 安卓TextView文字悬浮阴影效果实现
- TextView文字阴影效果。
- 使用 textview实现文字的阴影效果,浮雕效果
- 安卓:文字阴影
- Android TextView 显示文字阴影效果
- android TextView中文字的阴影效果
- 实现textview的阴影效果
- Android Textview实现阴影效果
- android自定义TextView实现安卓手机开机android文字Log的动画效果
- 安卓自定义TextView实现签到效果
- TextView显示文字过长时添加阴影渐变消失效果
- android 把TextView中的文字添加阴影效果
- TextView中的文字添加阴影效果及Style的使用
- Android TextView跑马灯效果与设置文字阴影
- AndroidTips(1):给TextView文字添加阴影效果
- TextView显示文字过长时添加阴影渐变消失效果
- Android TextView 文字阴影
- TextView加文字阴影
- 解决ligerUI关闭子窗口,无法刷新父界面的方法
- Elasticsearch学习笔记之二(ES集群)
- eclipse 修改contextroot导致spring springmvc加载2次
- Oracle闪回-非当前的还原表空间的恢复
- collectionAndMap
- 安卓TextView文字悬浮阴影效果实现
- 测试java
- UVa 1592 Database
- 通过串口log信息解决无限重启问题——空指针异常
- 2017开学训练第五周周中总结
- 解决CentOS下无法发送邮件的问题 + selinux
- 机器学习中的正则化
- Spring源码学习之认识AOP
- slf4j配置实例