这里有很多关于cardview提升的问题,我尝试了解决问题的所有解决方案,但它仍然无效。我添加了card_view:cardUseCompatPadding =" true"进入cardview,我也尝试在android清单中将硬件加速设置为true。我还读到,如果我在cardview中使用填充,它可能会切出卡片视图的阴影。谁能让我知道我做错了什么。我可以在android studio中看到阴影,但不能在模拟器或真实设备上看到阴影。
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="20dp"
card_view:cardBackgroundColor="@android:color/white"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="6dp"
android:id="@+id/cardView"
card_view:cardUseCompatPadding="true"
>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/horizontal_spacing">
<ImageView
android:id="@+id/imageView"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_gravity="end"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/aboutpallogo"/>
<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:textSize="14dp"
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
android:textColor="#171652"
android:textDirection="rtl"
app:layout_constraintBottom_toBottomOf="@+id/imageView"
app:layout_constraintEnd_toStartOf="@+id/imageView"
app:layout_constraintStart_toStartOf="parent"
tools:text="Header"/>
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="TextView"
android:textDirection="rtl"
android:textColor="#4cbea9"
app:layout_constraintEnd_toEndOf="@+id/textView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"/>
<View
android:id="@+id/divider"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginTop="8dp"
android:background="@drawable/divider"
app:layout_constraintEnd_toEndOf="@+id/textView2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2"/>
<com.mediamer.apps.pal_library.helpers.ExpandableTextView
android:id="@+id/expandableTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="24dp"
app:expanded="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/textView2"
app:layout_constraintEnd_toStartOf="@+id/imageView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider"
/>
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
答案 0 :(得分:0)
尝试放
android:elevation="6dp"
在
<android.support.v7.widget.CardView
部分。此外,您如何使用此Cardview的信息可能很有用。
答案 1 :(得分:0)
请改用此代码:
<android.support.v7.widget.CardView
android:id="@+id/report_details_card"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardBackgroundColor="@color/colorWhite"
app:cardCornerRadius="@dimen/cardview_default_radius"
app:cardElevation="@dimen/cardview_default_elevation"
app:cardUseCompatPadding="true">
</android.support.v7.widget.CardView>
您只需要替换
card_view:cardCornerRadius="4dp"
card_view:cardElevation="6dp"
card_view:cardUseCompatPadding="true"
带
app:cardUseCompatPadding="true"
app:cardCornerRadius="4dp"
app:cardElevation="6dp"
现在你很高兴。快乐的编码:)