CardView not showing Shadow in Android L
After going through the docs again, I finally found the solution.
Just add card_view:cardUseCompatPadding="true"
to your CardView
and shadows will appear on Lollipop devices.
What happens is, the content area in a CardView
take different sizes on pre-lollipop and lollipop devices. So in lollipop devices the shadow is actually covered by the card so its not visible. By adding this attribute the content area remains the same across all devices and the shadow becomes visible.
My xml code is like :
<android.support.v7.widget.CardView
android:id="@+id/media_card_view"
android:layout_width="match_parent"
android:layout_height="130dp"
card_view:cardBackgroundColor="@android:color/white"
card_view:cardElevation="2dp"
card_view:cardUseCompatPadding="true"
>
...
</android.support.v7.widget.CardView>
CardView not showing shadow elevation
Do not forget that to draw shadow you must use hardwareAccelerated drawing
<application android:hardwareAccelerated="true" ...>
see for details
https://developer.android.com/guide/topics/graphics/hardware-accel.html?hl=ru
Shadow not showing on Androidx Cardview
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.
Cardview shadow not appearing in lollipop devices?
After going through the docs again, I finally found the solution.
Just add card_view:cardUseCompatPadding="true"
to your CardView
and shadows will appear on Lollipop devices.
What happens is, the content area in a CardView
take different sizes on pre-lollipop and lollipop devices. So in lollipop devices the shadow is actually covered by the card so its not visible. By adding this attribute the content area remains the same across all devices and the shadow becomes visible.
My xml code is like :
<android.support.v7.widget.CardView
android:id="@+id/media_card_view"
android:layout_width="match_parent"
android:layout_height="130dp"
card_view:cardBackgroundColor="@android:color/white"
card_view:cardElevation="2sp"
card_view:cardUseCompatPadding="true"
>
...
</android.support.v7.widget.CardView>
Cardview suddenly stops showing shadow
I think it's not possible to cast shadows with
android:hardwareAccelerated="false"
. If it is strictly necessary in your app, one solution could be setting the acceleration by activities instead of application level.
<activity ... />
<activity android:hardwareAccelerated="" />
This way you could leave as android:hardwareAccelerated="false"
the activities where cardviews are not being used and the application level tag as true.
Related Topics
Google Maps API V2 'Failed to Load Map. Could Not Contact Google Servers'
Jpeg Images Have Different Pixel Values Across Multiple Devices
Certpathvalidatorexception:Trust Anchor for Certificate Path Not Found - Retrofit Android
Gridlayout and Row/Column Span Woe
Replacing Glreadpixels with Egl_Khr_Image_Base for Faster Pixel Copy
Android Check Permission for Locationmanager
A Failure Occurred While Executing Org.Jetbrains.Kotlin.Gradle.Internal.Kaptexecution
Android Fragments: When to Use Hide/Show or Add/Remove/Replace
Start Activity with an Animation
Java.Lang.Noclassdeffounderror: Android.Support.V7.Appcompat.R$Styleable
Why the View Keeps Flashing When Using Jetpack Navigation with Compose
Android Phone Orientation Overview Including Compass
Are Parameters in Strings.Xml Possible
How to Monitor Sim State Change
How to Make Drawerlayout to Display Below the Toolbar
Android Emulator Issues in New Versions - the Emulator Process Has Terminated