Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cardview shadow for ImageView

enter image description here

(1 screenshot - ImageView visibility is visible, 2 screenshot - gone)

When using ImageView with CardView we can say that shadow isn't visible at all (especially on the smartphone display)

<android.support.v7.widget.CardView
    android:id="@+id/ImageViewWrapper"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:elevation="0dp"
    android:layout_margin="10dp"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:cardCornerRadius="6dp">

    <android.support.v7.widget.AppCompatImageView
        android:id="@+id/ImageView"
        android:visibility="visible"
        android:background="@color/black_1000"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center_vertical"
        app:srcCompat="@drawable/ic_folder"/>

</android.support.v7.widget.CardView>

android:elevation doesn't make any effect (0dp, 5dp, or 20dp - nothing changes), so I just set it 0dp

Can we control this cardview shadow, make it stronger/bigger/thicker?

3 screenshot - here MX Player app example of video thumbnail ImageView (https://play.google.com/store/apps/details?id=com.mxtech.videoplayer.ad)

enter image description here

Update

I set app:cardElevation="7dp" and app:cardUseCompatPadding="true" No progress... and cardUseCompatPadding made my image height size smaller and now I have black bars at left/right

enter image description here

like image 609
user924 Avatar asked Mar 02 '18 19:03

user924


People also ask

What is the use of CardView in Android?

CardView is a new widget in Android that can be used to display any sort of data by providing a rounded corner layout along with a specific elevation. CardView is the view that can display views on top of each other. The main usage of CardView is that it helps to give a rich feel and look to the UI design.

How do I change the color of my card shadow?

Use Fake Shadow. xml ) in the parent layout which is looking like a shadow. You can replace FF46A9 in shadow. xml to change the color of shadow. Also android:backgroundTint="@color/colorShadow" works but you have to adjust colors alpha in shadow.


2 Answers

Use app:cardElevation="4dp"instead of android:elevation.

Also add this app:cardUseCompatPadding="true".

UPDATE

Also consider changing the CardView size to:

android:layout_width="wrap_content"
android:layout_height="wrap_content"
like image 148
Xenolion Avatar answered Sep 22 '22 06:09

Xenolion


Make sure enable hardware Acceleration

You can do it at application level:

<application android:hardwareAccelerated="true" ...>

Or activity level:

<application android:hardwareAccelerated="false">
    <activity ... />
    <activity android:hardwareAccelerated="true" />
</application>

Or Window level, view level, etc.

like image 34
Student222 Avatar answered Sep 25 '22 06:09

Student222