Android中的阴影文本视图

时间:2017-01-20 12:17:50

标签: android android-drawable

我正在尝试像这样的影子文字视图: enter image description here

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:gravity="top|center"
    android:background="@drawable/gradient">
        <TextView
            android:layout_width="300dp"
            android:layout_height="50dp"
            android:text="@string/ph"
            style="@style/TextBox"
            android:textSize="16sp"/>
 </LinearLayout>

gradient.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"  >
<item>
    <shape android:shape="rectangle">
        <gradient
            android:endColor="#FFFFFF"
            android:startColor="#FFFFFF"
            android:type="linear"
            android:centerColor="#E3F2FD"
            android:angle="90">
        </gradient>

    </shape>
</item>

此代码无法获取我的设计。 textview就像我的照片一样吗?

2 个答案:

答案 0 :(得分:0)

在这里,我尝试创建与您的要求相同的阴影,如下所示。我知道阴影颜色并不像你想要的那样模糊

enter image description here

<LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="@drawable/shadow"
        android:orientation="vertical"
        android:paddingBottom="5dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/rectangle_shape"
            android:padding="10dp"
            android:text="Phone Number" />
    </LinearLayout>

抽拉/ shadow.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#220000ff" />
    <corners android:radius="20dp" />
</shape>

抽拉/ rectangle_shape.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#FFFFFF" />
    <corners android:radius="20dp" />
</shape>

答案 1 :(得分:0)

制作xml backround_with_shadow并粘贴此代码 -

<?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item >
            <shape
                android:shape="rectangle">
                <solid android:color="#87ceeb" />
                <corners android:radius="5dp"/>
            </shape>
        </item>
and set xml as background of layout
        <item android:right="1dp" android:left="1dp" android:bottom="2dp">
            <shape
                android:shape="rectangle">
                <solid android:color="@android:color/white"/>
                <corners android:radius="5dp"/>
            </shape>
        </item>
    </layer-list>