android - 如何在与父级底部对齐的 CardView 上添加阴影

标签 android shadow cardview

我有一个底部与屏幕对齐的 CardView,尽管我想在 CardView 的顶部添加更多阴影。我试过

  android:shadowColor="#000"
  android:shadowDx="0"
  android:shadowDy="30"
  android:shadowRadius="50"

但是没有看到任何变化,这是我的代码:

    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:clipToPadding="false"
        android:clipChildren="false"
         android:orientation="vertical"
         android:layout_width="match_parent"
         android:layout_height="match_parent">

    <!--rest of the code-->

     <LinearLayout
            android:layout_width="match_parent"
            android:layout_alignParentBottom="true"
            android:shadowColor="#000"
            android:shadowDx="0"
            android:shadowDy="30"
            android:shadowRadius="50"
            android:layout_height="wrap_content">
        <android.support.v7.widget.CardView      
xmlns:app="http://schemas.android.com/apk/res-auto"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:elevation="8dp"                         
             android:divider="@android:color/transparent"
             android:dividerHeight="0.0px"
             android:clipToPadding="false"
             android:clipChildren="false"
             app:cardElevation="10dp"
             app:cardPreventCornerOverlap="false">

          <!--rest of the code-->
    </android.support.v7.widget.CardView>
    </LinearLayout>

    </RelativeLayout>

最佳答案

边缘并没有太大帮助,所以我在主容器上放置了填充并删除了所有那些阴影属性,因为 android:elevation="" 正在做这项工作。

这里有一些清晰的代码,可以满足这种需求:

<RelativeLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:clipToPadding="false"
        android:clipChildren="false"
        android:orientation="vertical"
        android:padding="20dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

  <!--rest of the code-->

  <LinearLayout
         android:layout_width="match_parent"
         android:layout_alignParentBottom="true"
         android:clipToPadding="false"
       android:clipChildren="false"
         android:layout_height="wrap_content">
    <android.support.v7.widget.CardView
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:elevation="8dp"
         android:divider="@android:color/transparent"
         android:dividerHeight="0.0px"
         android:clipToPadding="false"
         android:clipChildren="false"
         card_view:cardElevation="10dp"
         card_view:cardPreventCornerOverlap="false">

      <TextView
          android:layout_width="match_parent"
          android:padding="20dp"
          android:layout_height="wrap_content"
          android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
          do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim 
          veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
          consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
          cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident,
          sunt in culpa qui officia deserunt mollit anim id est laborum"
        />   
    </android.support.v7.widget.CardView>
  </LinearLayout>

</RelativeLayout>

还有一张关于它的外观的图片: enter image description here

关于android - 如何在与父级底部对齐的 CardView 上添加阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41615468/

相关文章:

java - 尝试连接 BluetoothGatt 时回调中出现未处理的异常

android - 插件太旧,请更新到最新版本,或将 ANDROID_DAILY_OVERRIDE 环境变量设置为

Java,paintComponent中的setForeground融化了CPU

Three.js 阴影无法正常工作

android - 错误 :(34) No resource identifier found for attribute 'srcCompat' in package 'com.hackerinside.jaisonjoseph.radioplanet'

android - IllegalStateException:RecyclerView 正在计算布局或滚动时无法调用此方法

android - 在安卓中分享

javascript - 在体素地形上点亮/转换阴影的有效方法

Android 在 Recyclerview 中使用 itemTouchHelper 在cardview上拖动海拔翻译z

Android CardView - 如何折叠角