Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to apply shadow to the ImageView. When I'm applying shadow to a TextView I'm getting it but same it's not getting to ImageView. How can I solve this problem?

question from:https://stackoverflow.com/questions/8353149/how-to-apply-shadow-to-imageview

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
227 views
Welcome To Ask or Share your Answers For Others

1 Answer

We can also use CardView which provides a rounded corner background and shadow. To use that you need to add the v7 CardView library as a dependency to the project in the build.gradle like below.

dependencies {
    compile 'com.android.support:cardview-v7:23.0.1'
    -------
}

Note: Change 23.0.1 in the above line with the respected version.

So I surrounded the ImageView with CardView to make shadow like below.

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    card_view:cardBackgroundColor="@android:color/white">

    <ImageView
        android:id="@+id/dish_image"
        android:layout_width="match_parent"
        android:layout_height="120dp"
        android:adjustViewBounds="true" />

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

It'll add a shadow around the image.

Note: I don't know whether it is a good workaround. I am a beginner. I tried to implement the CardView which gives an idea to implement the same for this. If it is not good please update me with the reason.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...