Shadow in CardView not working. When i Put anything in Card View, corners in CardView gone disappear too. In Preview tools in Android Studio look like very good but for all my devices not look lilke similar. I working on Android 9.0. It is problem with this version?
My version of material design implementation("com.google.android.material:material:1.3.0")
Preview in Android Studio tools
What showing on my tablet screen
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="130dp"
android:layout_height="180dp"
android:layout_margin="10dp"
android:background="@android:color/transparent">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
app:cardBackgroundColor="@color/white"
app:cardCornerRadius="5dp"
app:cardElevation="4dp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/relative_image_view"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.75"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/itemImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:background="@drawable/emaenu_game"
android:contentDescription="@string/picture"
android:scaleType="centerCrop" />
</RelativeLayout>
<View
android:id="@+id/view10"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@color/main_emenu"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.25"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/relative_image_view" />
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:fontFamily="@font/poppins"
android:gravity="center"
android:minHeight="0dp"
android:paddingStart="15dp"
android:paddingTop="2dp"
android:paddingEnd="15dp"
android:text="Water Flow"
android:textAllCaps="false"
android:textColor="@color/black_emenu"
android:textSize="12sp"
android:textStyle="normal"
app:layout_constraintBottom_toBottomOf="@+id/view10"
app:layout_constraintEnd_toEndOf="@+id/view10"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/relative_image_view" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
Please add this to cardView
app:cardElevation="3dp"
app:cardCornerRadius="16dp"
Please remove this 2 line
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true"
And CardView will be Parent layout not ConstraintLayout so Please remove upper ConstraintLayout.
<com.google.android.material.card.MaterialCardView
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_height="match_parent"
android:layout_width="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/AnyColor">
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
I am sure after this it will show shadow and corner radius.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.