Cardview shadow for ImageView

℡╲_俬逩灬. 提交于 2019-12-24 15:13:03

问题


(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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!