TextView加文字阴影

作者: shone | 来源:发表于2016-06-17 10:33 被阅读1345次

    偶然看到哔哩title的文字跟其它地方显示不一样

    详情页

    查了一下用到了textview的相关属性.

    通常一些像Photoshop这样的工具可以用来创建各种各样的文字效果,并且我们经常用到的一种效果就是阴影。Android是支持字体阴影的。在TextView中实现字体阴影效果比在位图元素中的效率更高,并且使得设计可适配多种屏幕尺寸。相同条件下,Android的LayoutManager缩放TextView控件可比在ImageView中缩放位图要简单多了。字体阴影需要四个相关参数:

    1. android:shadowColor:阴影的颜色
    2. android:shadowDx:水平方向上的偏移量
    3. android:shadowDy:垂直方向上的偏移量
    4. android:shadowRadius:阴影的范围

    看看哔哩的实现:

                    <TextView
                        android:id="@id/title"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_alignTop="@id/cover"
                        android:layout_marginLeft="@dimen/item_spacing"
                        android:layout_marginRight="@dimen/item_spacing"
                        android:layout_marginTop="-2.0dip"
                        android:layout_toRightOf="@id/cover"
                        android:shadowColor="@color/black_light"
                        android:shadowDx="1.0"
                        android:shadowDy="1.0"
                        android:shadowRadius="2.0"
                        android:singleLine="true"
                        android:textAppearance="@style/TextAppearance.App.Headline"
                        android:textColor="@color/white" />
    

    相关文章

      网友评论

      本文标题:TextView加文字阴影

      本文链接:https://www.haomeiwen.com/subject/eehvdttx.html