问题
(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)
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
回答1:
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"
回答2:
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.
来源:https://stackoverflow.com/questions/49076188/cardview-shadow-for-imageview