Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fading the image border in an imageview

I need to add a fading effect on a ImageView. In my situation I have a RelativeLayout, the relative background in yellow and in the center of that background there is a ImageView. Now I need to apply a fade affect on the edge of the ImageView. Is this possible? (Android api 11+)

I tried:

android:requiresFadingEdge="horizontal"
android:fadingEdge="horizontal"
android:fadingEdge="vertical"
android:fadingEdgeLength="40px"

but doesn't work..

enter image description here

This is an example of what I want. Like you can see the top and the left are fading, the right and bottom edge, instead, are not fading..

Thanks a lot!

like image 644
Pompeo Romeo Avatar asked Oct 04 '22 04:10

Pompeo Romeo


1 Answers

Override methods in ImageView as written below:

private float FadeStrength = 1.0f;
private int FadeLength = 40px;

@Override
protected float getTopFadingEdgeStrength() {
    return FadeStrength;
}

@Override
protected float getBottomFadingEdgeStrength() {
    return FadeStrength;
}

@Override
protected float getLeftFadingEdgeStrength() {
    return FadeStrength;
}

@Override
protected float getRightFadingEdgeStrength() {
    return FadeStrength;
}

And on initialization of view add lines:

setFadingEdgeLength(FadeLength);
setVerticalFadingEdgeEnabled(true);
setHorizontalFadingEdgeEnabled(true);
like image 168
LbISS Avatar answered Oct 07 '22 17:10

LbISS