通常一些像Photoshop这样的工具可以用来创建各种各样的文字效果,并且我们经常用到的一种效果就是阴影。Android是支持字体阴影的,在这片文章中,我们将会探讨各种创建阴影的方式。在TextView中实现字体阴影效果比在位图元素中的效率更高,并且使得设计可适配多种屏幕尺寸。相同条件下,Android的LayoutManager缩放TextView控件可比在ImageView中缩放位图要简单多了。
字体阴影需要四个相关参数:
1. android:shadowColor:阴影的颜色
2. android:shadowDx:水平方向上的偏移量
3. android:shadowDy:垂直方向上的偏移量
4. android:shadowRadius:阴影的范围
还有一件事情是,我们可以通过改变偏移量来有效的改变光源的方向:
- < span>LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:background="@color/White"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"<
- < span>TextViewandroid:textColor="@color/Black"
- android:layout_width="wrap_content"
- android:text="Soft Shadow (Below)"
- android:layout_height="wrap_content"
- android:padding="2dp"
- android:shadowColor="@color/TransparentGrey"
- android:shadowDx="3"
- android:shadowDy="-3"
- android:shadowRadius="1.5"/<
- </>LinearLayout
如图样式