繁体   English   中英

Cardview 未在底部显示阴影

[英]Cardview not showing shadow along bottom

我有以下用于cardview的xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent" android:padding="2dp">
<!-- A CardView that contains a TextView -->
<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/card_view"
    android:layout_gravity="center"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    card_view:cardCornerRadius="0dp">
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="5dp">
        <TextView
            android:id="@+id/info_text"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </FrameLayout>
</android.support.v7.widget.CardView>
</LinearLayout>

这导致这些阴影在底部根本没有阴影

http://i.imgur.com/xNoIDR4.png

但我试图得到类似这个阴影的东西,更好地围绕整个卡片。

在此处输入图片说明

我试着改变海拔无济于事,和搜索在这个问题上,似乎带来了什么,但一个没有阴影的人,在这不是我的情况下,所有的问题。

我怎样才能得到正确的阴影?

谢谢。

您需要在卡片视图中添加此 xml 属性

应用程序:cardUseCompatPadding="true"

clipChildren="false"添加到父LinearLayout也应该有效。

使用 card_view:cardElevation 属性设置高程

在您的 cardView 中添加这些行

    android:layout_marginTop="5dp"
    android:layout_marginBottom="5dp"

我遇到了同样的问题,直到我记得如果父级正在包装其内容,那么它就不会包装阴影,所以我给了父级比子级更大的尺寸,这样它将包括子级和子级的阴影

 <androidx.constraintlayout.widget.ConstraintLayout 
 xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="110dp"
android:layout_height="110dp">

<androidx.cardview.widget.CardView xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:card_view="http://schemas.android.com/tools"
    android:layout_width="98dp"
    android:layout_height="98dp"
    app:cardCornerRadius="10dp"
    app:cardElevation="5dp"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <androidx.appcompat.widget.AppCompatImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        app:srcCompat="@drawable/manhattan" />

  
</androidx.cardview.widget.CardView>

  </androidx.constraintlayout.widget.ConstraintLayout>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM