【问题标题】:Android Card View Shadow in each sideAndroid Card View Shadow 在每一侧
【发布时间】:2021-05-26 14:02:14
【问题描述】:

我希望卡片视图的每一侧都有相同的阴影,如下图在棒棒糖设备及以上设备上:

【问题讨论】:

    标签: android cardview


    【解决方案1】:

    我希望这对你有用。您可以尝试使用app:cardElevation="8dp" 属性并更改值以满足您的需要。请记住先将此属性添加到父布局中,尽管xmlns:app="http://schemas.android.com/apk/res-auto"

    下面的例子

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    
        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:padding="10dp"
            app:cardCornerRadius="10dp"
            app:cardElevation="8dp">
    
        </androidx.cardview.widget.CardView>
    
    </RelativeLayout>
    

    至于圆角,您可以使用app:cardCornerRadius="10dp" 并根据需要调整值。

    【讨论】:

    • 卡片视图实现了材料设计指南,并在其上放置了启用光的阴影我曾尝试过 cardElevation,但对我没有帮助
    【解决方案2】:

    关键是使用 android:elevation="@dimen/_4sdp"。

     <androidx.cardview.widget.CardView
        android:id="@+id/card"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/_4sdp"
        android:background="@drawable/bg_white"
        android:elevation="@dimen/_4sdp"
        app:cardCornerRadius="@dimen/_8sdp">
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-24
      • 1970-01-01
      • 2015-07-01
      • 2011-08-02
      相关资源
      最近更新 更多