Add glow/shadow in ImageView

0

What I am trying to achieve:

enter image description here

What I am able to achieve:

enter image description here

Code:

<de.hdodenhof.circleimageview.CircleImageView
        android:padding="5dp"
        android:background="@drawable/sub_cat_background"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:id="@+id/tab_image"
        android:src="@drawable/mehendi_tab"
        android:layout_gravity="center_horizontal"/>

sub_cat_background.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:innerRadius="0dp"
       android:shape="ring"
       android:thicknessRatio="2"
       android:useLevel="false" >
    <solid android:color="@android:color/transparent" />

    <stroke
        android:width="5dp"
        android:color="@color/white" />
</shape>

This is what I am able to get after King of masses suggestions:

Now How would I change the grey ring to shadow effect as shown in above figure enter image description here

Edit 4:

I tried with the canvas way also.

For this,So instead of setting the white ring with the xml, I am using the image with white circle as shown above(image 2).

 Bitmap bitmap=BitmapFactory.decodeResource(getResources(),R.drawable.salon_selected);

            int imageMaxSize = Math.max(bitmap.getWidth(), bitmap.getHeight());


            RadialGradient gradient = new RadialGradient(imageMaxSize / 2, imageMaxSize / 2, imageMaxSize / 2,
                    new int[] {0xFFFFFFFF, 0xFFFFFFFF, 0x00FFFFFF},
                    new float[] {0.0f, 0.8f, 1.0f},
                    android.graphics.Shader.TileMode.CLAMP);
            Paint paint = new Paint();
            paint.setShader(gradient);


            Canvas canvas=new Canvas();
// in onDraw(Canvas)
            canvas.drawBitmap(bitmap, 0.0f, 0.0f, paint);

            tabImage.setImageBitmap(bitmap);

But I didn't get any effect, Code source (How to achieve feathering effect in Android?)

android
animation
imageview
glow
asked on Stack Overflow Sep 22, 2017 by Ankur_009 • edited Sep 26, 2017 by Ankur_009

2 Answers

0

In android studio there is in build drawable that you can use for apply shadow to any View. That is similar like a drop shadow.

android:background="@drawable/abc_menu_dropdown_panel_holo_light"

Using this you can not change the background color of the view & its border color. If you want your own custom drawable then use layer-list

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!--the shadow comes from here-->
    <item
        android:bottom="0dp"
        android:drawable="@android:drawable/dialog_holo_light_frame"
        android:left="0dp"
        android:right="0dp"
        android:top="0dp">

    </item>

    <item
        android:bottom="2dp"
        android:left="2dp"
        android:right="2dp"
        android:top="2dp">
        <!--whatever you want in the background, here i preferred solid white -->
        <shape android:shape="rectangle">
            <solid android:color="@android:color/white" />

        </shape>
    </item>
</layer-list>

and apply to your view like below

android:background="@drawable/custom_drop_shadow_drawable"

If this not work you can try something like this with ShadowImageView

answered on Stack Overflow Sep 22, 2017 by King of Masses
0

By playing with these attributes you can get glow and shadow effects

android:shadowColor
android:shadowDx
android:shadowDy
android:shadowRadius

Should you need to achieve the same effect programatically. Android provides the following shadow related API.

public void setShadowLayer (float radius, float dx, float dy, int color)

So, I tried it with some different fonts, shadow settings, colors and transparency settings.

here is a results image

you can also do this with any view i.e imageview, button, textview etc.

source code for reference

answered on Stack Overflow Sep 22, 2017 by Nouman Ch

User contributions licensed under CC BY-SA 3.0