简体   繁体   中英

card view elevation not showing up

There are many questions about cardview elevation here and i tried all the solution to solve the problem but it is still not working. I have added card_view:cardUseCompatPadding="true" into cardview and i have also tried to set hardware acceleration to true in android manifest. I also read that if i use padding in cardview it might cut out the shadows for card view. can someone let me know what am i doing wrong. I can see the shadows in android studio but not on the emulator or real device.

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

Try putting

android:elevation="6dp"

in

 <android.support.v7.widget.CardView

section. Also the information of how are you using this Cardview may be useful.

Use this code instead :

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

You just have to replace

  card_view:cardCornerRadius="4dp"
  card_view:cardElevation="6dp"
  card_view:cardUseCompatPadding="true"

with

  app:cardUseCompatPadding="true"
  app:cardCornerRadius="4dp"
  app:cardElevation="6dp"

Now you are good to go. Happy coding :)

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.

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