如何使卡片视图仅显示底部阴影

15

我使用以下代码:

<android.support.v7.widget.CardView
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardUseCompatPadding="true"
        app:cardElevation="4dp">
    <TextView android:text="in card view" android:layout_width="match_parent" android:layout_height="wrap_content"/>
</android.support.v7.widget.CardView>

截图如下:

enter image description here

如何只让底部显示阴影?


1
希望能够控制阴影,也在寻找同样的答案。 - Gustavo Baiocchi Costa
5
去除此行:app:cardUseCompatPadding="true" - Benjamin
1
@Benjamin,这会改变什么? - CoolMind
1个回答

5
如果您想要一个线性阴影,可以尝试以下方法:
<View
    android:id="@+id/shadow"
    android:layout_width="match_parent"
    android:layout_height="3dp"
    android:background="@drawable/down_shadow"
    />

down_shadow.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"
    >

    <gradient
        android:angle="-90"
        android:endColor="#EEEEEE"
        android:startColor="#FFFFFF"
        />

</shape>

您还可以查看其他手动设置阴影的文章,例如:https://medium.com/@ArmanSo/take-control-of-views-shadow-android-c6b35ba573e9


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接