褪色边缘仅在顶部和左侧起作用 [英] fading edges working only on top and left

查看:133
本文介绍了褪色边缘仅在顶部和左侧起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个自定义的ImageView,它支持通过GestureDetector中的View.scrollBy()调用进行基本滚动.我想添加一些有关达到滚动范围的反馈,所以我启用了衰落功能:

I made a custom ImageView that supports basic scrolling through calls to View.scrollBy() in a GestureDetector. I wanted to add some feedback on the reaching of scrolling bounds so I enabled fading with:

setVerticalFadingEdgeEnabled(true);
setHorizontalFadingEdgeEnabled(true);

,但褪色仅在顶部和左侧边缘起作用,而底部和右侧则不会褪色.我确定这些边缘不会在屏幕外,因为视图的高度和宽度设置为fill_parent.那怎么了?

but the fading works as I expected only on top and left edges, while bottom and right ones don't fade. I'm sure those edges aren't off screen because the view is set to fill_parent in height and width. So what's wrong?

仅启用垂直/水平衰落边缘可确认仅绘制了顶部/左侧边缘.现在,我正在尝试阅读

enabling only vertical/horizontal fading edges confirms that only top/left edges get drawn. Now I'm trying to read View.java (6870 an on)...

推荐答案

问题似乎出在getBottomFadingEdgeStrength()getRightFadingEdgeStrength()上,或者更好,因为我没有重写它们以使用自定义项视图.

It seems that the problem is in getBottomFadingEdgeStrength() and getRightFadingEdgeStrength(), or better, in the fact that I didn't override them to work with my custom view.

这些受保护的方法告诉视图的draw()何时绘制褪色(以及着色的强度-当接近滚动限制时,查看ScrollView的作用).

These protected methods tell view's draw() when to draw the fadings (and how strongly -- see what a ScrollView does when you get close to the scrolling limit).

对于上边缘和左边缘,这很容易,因为在两种情况下限制均为0并且默认实现有效(以开/关方式),但是对于其他两个,我需要重写方法以考虑到我自己的滚动范围(在我的情况下是可绘制的尺寸).

For top and left edges it's easy because the limit is 0 in both cases and the default implementation works (in its on/off manner), but for the other two I need to override the methods to take into account my own scrolling bounds (in my case, the drawable dimensions).

这篇关于褪色边缘仅在顶部和左侧起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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