如何在CardView上添加阴影,使其与父对象的底部对齐 [英] How to add shadow on CardView aligned to bottom of parent

查看:124
本文介绍了如何在CardView上添加阴影,使其与父对象的底部对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的CardView底部与屏幕对齐,尽管标高我想在CardView顶部添加更多阴影.我已经尝试过

I have a CardView aligned bottom to screen, destpite the elevation I want to add more shadow to top of the CardView. I've tried with

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

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

But see no changes this is my code:

    <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=""是工作的基础.

Well margin don't help much, so I put padding on main container and remove all those shadow properties because the android:elevation="" is what is doing the job.

以下是一些清晰的代码,可以满足以下需求:

Here is some clear code, that is working for this need:

<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>

以及有关其外观的图片:

And an image on how this looks:

这篇关于如何在CardView上添加阴影,使其与父对象的底部对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆