I am working with cardviews but the problem is my CardView is not showing any elevation or shadow. I have already tried some of the methods suggested in stackoverflow answer
The answer is a combination of margin and padding of cardView and its parent.
Try like this:
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/minimum_dimem"
android:layout_marginLeft="@dimen/default_margin"
android:layout_marginRight="@dimen/default_margin"
android:layout_marginTop="@dimen/minimum_dimem"
app:cardBackgroundColor="@color/white"
app:cardCornerRadius="@dimen/cardview_radius"
app:cardElevation="@dimen/cardview_default_elevation">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/ten_dimem">
...
</RelativeLayout>
</android.support.v7.widget.CardView>
And the result:
<android.support.design.card.MaterialCardView
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"
xmlns:card_view="http://schemas.android.com/tools"
app:cardCornerRadius="@dimen/_5sdp"
card_view:cardCornerRadius="3dp"
android:layout_margin="@dimen/_3sdp"
card_view:cardElevation="10dp"
card_view:cardUseCompatPadding="true">
</android.support.design.card.MaterialCardView>
Use above code and don't forget to use android:hardwareAccelerated="true"
.
It will work definitely.
You should have to try this:
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:cardElevation="3dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
<!--Put your other fields between this-->
</android.support.v7.widget.CardView>
There are two things that helped me solve this problem:
Setting this in the application tag of my manifest:
android:hardwareAccelerated="false"
File > Invalidate cache and restart
Try putting this in your rootview:
xmlns:card_view="http://schemas.android.com/apk/res-auto"
and use this code for elevation:
card_view:cardElevation="10dp"
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