如何使Android ScrollView衰落边缘始终可见? [英] How to make Android ScrollView fading edge always visible?
问题描述
默认情况下,只有在可以朝该方向滚动时,滚动视图的衰落边缘才可见.如何使它始终可见?
By default scrollview's fading edge is visible only if it is possible to scroll in that direction. How can I make it visible at all times?
我不想将任何可绘制对象放在上面或类似的东西上.我想使用内置的衰落边缘来实现它,可能是通过重写一些scrollview函数来实现的.
I don't want to put any drawables on top or something like that. I want to accomplish it using the builtin fading edge, probably by overriding some scrollview functions.
推荐答案
是的,扩展ScrollView并重写这些方法(基于Donut-release2):
Yes, extend ScrollView and override these methods (based on Donut-release2):
@Override
protected float getTopFadingEdgeStrength() {
if (getChildCount() == 0) {
return 0.0f;
}
return 1.0f;
}
@Override
protected float getBottomFadingEdgeStrength() {
if (getChildCount() == 0) {
return 0.0f;
}
return 1.0f;
}
为了比较起见,这是原始代码,当您靠近列表末尾时,它会缩短褪色边缘:
For comparison's sake, this is the original code, which shortens the fading edge as you get close to the end of the list:
@Override
protected float getTopFadingEdgeStrength() {
if (getChildCount() == 0) {
return 0.0f;
}
final int length = getVerticalFadingEdgeLength();
if (mScrollY < length) {
return mScrollY / (float) length;
}
return 1.0f;
}
@Override
protected float getBottomFadingEdgeStrength() {
if (getChildCount() == 0) {
return 0.0f;
}
final int length = getVerticalFadingEdgeLength();
final int bottomEdge = getHeight() - mPaddingBottom;
final int span = getChildAt(0).getBottom() - mScrollY - bottomEdge;
if (span < length) {
return span / (float) length;
}
return 1.0f;
}
这篇关于如何使Android ScrollView衰落边缘始终可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!