7

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

user924
  • 8,146
  • 7
  • 57
  • 139
  • https://stackoverflow.com/questions/27599603/cardview-not-showing-shadow-in-android-l/33044134 – duggu Mar 02 '18 at 19:45
  • @duggu I have shadow, it's different problem – user924 Mar 02 '18 at 19:56
  • Why are you using `android.support.v7.widget.AppCompatImageView` instead of `ImagefView` ?? Is there any reason? – Xenolion Mar 02 '18 at 20:06
  • @Xenolion `ImageView` usually is always `AppCompatImageView`, but in some cases we have to explicitly set `AppCompatImageView` if, for example, using custom list item xml for RecyclerView and inflating like `View view = LayoutInflater.from(mContext).inflate(R.layout.list_item, parent, false);` – user924 Mar 02 '18 at 20:11
  • @Xenolion *AppCompatImageView will automatically be used when you use ImageView in your layouts and the top-level activity / dialog is provided by appcompat. You should only need to manually use this class when writing custom views.* https://developer.android.com/reference/android/support/v7/widget/AppCompatImageView.html – user924 Mar 02 '18 at 20:16
  • I have got it, thank you I have understood. But I think your image is on top of the card view. Try adding some padding in the cardview as a test? – Xenolion Mar 02 '18 at 20:20
  • @Xenolion I just think CardView shadow is weak and visibility is good only if CardView's content not that filled and colored (like mine) – user924 Mar 02 '18 at 20:32

2 Answers2

3

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"
Xenolion
  • 12,035
  • 7
  • 33
  • 48
1

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.

Student222
  • 3,021
  • 2
  • 19
  • 24