问题描述
我需要在ImageView
上添加淡入淡出效果.在我的情况下,我有一个RelativeLayout
,相对背景为黄色,在该背景的中心有一个ImageView
.现在,我需要在ImageView
的边缘上应用淡入淡出效果.这可能吗? (Android api 11+
)
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+
)
我尝试过:
android:requiresFadingEdge="horizontal"
android:fadingEdge="horizontal"
android:fadingEdge="vertical"
android:fadingEdgeLength="40px"
但不起作用.
这是我想要的例子.就像您可以看到顶部和左侧正在褪色,而右侧和底部边缘未在褪色..
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..
非常感谢!
推荐答案
重写ImageView中的方法,如下所示:
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);
这篇关于在imageview中淡化图像边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!