Android的滚动型衰退边缘 [英] Android ScrollView fading edge

查看:709
本文介绍了Android的滚动型衰退边缘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认滚动视图的衰落边缘是可见的,只有当它是可能在该方向上滚动。我怎样才能使它在任何时候都可见?

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?

我不想把任何可绘制在顶部或类似的东西。我想用它内建的衰落边缘,可能是压倒一切的一些滚动型的功能来完成。

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.

在此先感谢

推荐答案

是的,滚动型延伸并覆盖这些方法(基于甜甜圈-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;
}

有关比较的缘故,这是原来的code,从而缩短了衰退的边缘,你去接近列表的末尾:

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的滚动型衰退边缘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆