以下CSS, 在 android view xml 中怎么写?

border-radius: 5px;
background-image: linear-gradient(-179deg, #FAD961 0%, #F76B1C 100%);
border: 1px solid #8B572A;
box-shadow:         0px 1px 1px 0px rgba(0,0,0,0.30), inset 0px 1px 1px 0px rgba(255,255,255,0.60);
阅读 4.7k
1 个回答

安卓的xml文件里没有提供类似shadow的属性,所以只能取得近似的效果

下面是一个LayerDrawable文件,里面包含两个Rectangle

<?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="#4c000000" />

            <corners android:radius="5dip" />
        </shape>
    </item>
    <!-- 背景 -->
    <item
        android:bottom="1dip"
        android:right="1dip">
        <shape android:shape="rectangle" >
            <gradient
                android:angle="270"
                android:endColor="#F76B1C"
                android:startColor="#FAD961" />

            <corners android:radius="5dip" />

            <stroke
                android:width="1dip"
                android:color="#8B572A" />
        </shape>
    </item>

</layer-list>

下面是布局代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="10dp" >

    <TextView
        android:id="@+id/divview"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:background="@drawable/shadowdiv" />

</LinearLayout>

效果图:
近似的效果图

说明:不知道怎么实现CSS中的内阴影,求大神告知!

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题