Reputation: 9123
My layout file:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
tools:context=".TurnOnLocation">
<LinearLayout
android:id="@+id/requires_location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@id/turn_on_location">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="4dp"
app:cardElevation="10dp"
app:cardPreventCornerOverlap="false">
<TextView
android:id="@+id/info_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingStart="60dp"
android:paddingEnd="60dp"
android:textSize="28sp"
android:text="test"
android:textColor="@color/colorPrimary"
android:textAlignment="center"
android:background="@color/colorPrimaryDark" />
</androidx.cardview.widget.CardView>
</LinearLayout>
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/turn_on_location"
android:textColor="@color/colorPrimary"
android:textSize="@dimen/medium_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/turn_on_location"
app:layout_constraintTop_toBottomOf="@id/requires_location"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
I've specified the app:cardElevation="10dp"
which I believe is meant to render the drop shadow. However no shadow is appearing.
Any idea why?
Upvotes: 0
Views: 4994
Reputation: 3621
Use this Code, for me its works! the idea is on app:cardUserCompatPadding="true"
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@android:color/transparent"
app:cardElevation="4dp"
app:cardUseCompatPadding="true"
app:cardCornerRadius="4dp"
android:layout_marginVertical="@dimen/two_x"
app:cardBackgroundColor="@color/white">
Result
Upvotes: 2
Reputation: 11744
You've no mistake in your source code. The shadow should be rendered correctly. You might be checking the output in your layout preview. It has some issue on rendering. Please run the app in emulator or real device.
Upvotes: 2
Reputation: 1469
Add this line to your AndroidManifest
this android:hardwareAccelerated="true"
in application
tag
Upvotes: 2
Reputation: 243
Try this
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="4dp"
app:cardElevation="10dp"
android:layout_margin="16dp">
</androidx.cardview.widget.CardView
Upvotes: 0
Reputation: 350
add below lines into CardView tag
card_view:cardBackgroundColor="@android:color/white"
card_view:cardElevation="2dp"
card_view:cardUseCompatPadding="true"
Upvotes: 0