写界面时遇到了这么一个需求:在“请输入标题...”那栏下面添加阴影效果。
一开始我想直接用android: elevation属性的,但是没效果,最后决定画一个。。。
(UI效果图如下)
在drawable里新建一个shadow.xml文件,代码如下
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="@android:color/transparent"
android:endColor="#33000000"
android:angle="90">
</gradient>
</shape>
在布局文件里调用:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layoutMarginSmall"
android:background="@color/background_white_FA">
<!-- 你的View放在这里 -->
<EditText
android:id="@+id/et_newLog_title"
android:layout_width="match_parent"
android:layout_height="44dp"
android:hint="@string/newLog_hint_title"
android:gravity="center_vertical"
android:textSize="@dimen/fontSizeExtraSmall"
android:paddingStart="@dimen/layoutSafeMargin"
android:paddingEnd="@dimen/layoutSafeMargin"
android:background="@null" />
<View
android:layout_below="@+id/et_newLog_title"
android:layout_width="match_parent"
android:layout_height="@dimen/layoutMarginSmall"
android:background="@drawable/shadow"/>
</RelativeLayout>
最终效果如下: