我知道如何从滚动条禁用fadingedge,但我需要的是在不禁用顶部渐弱边缘效果的情况下禁用底部渐变边缘,这可能吗?
答案 0 :(得分:13)
您可以通过扩展ScrollView并覆盖这两种方法之一来实现所需的效果:
float getTopFadingEdgeStrength()
float getBottomFadingEdgeStrength()
他们会让你改变衰落边缘的大小 - 只需将底部值设置为0,你就可以了:)
关闭底部淡出的代码示例:
/**
* Created by scana on 14.12.14.
*/
public class TopFadeEdgeScrollView extends ScrollView {
public TopFadeEdgeScrollView(Context context) {
super(context);
}
public TopFadeEdgeScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public TopFadeEdgeScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected float getBottomFadingEdgeStrength() {
return 0.0f;
}
}
答案 1 :(得分:0)
斯堪纳的答案是正确的。
这是他的答案的科特林版本,其中包含禁用特定边缘的方法。
import android.content.Context
import android.util.AttributeSet
import android.widget.ScrollView
class FadingEdgeScrollView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyle: Int = 0
) : ScrollView(context, attrs, defStyle) {
var topFadingStrength: Float? = null
var bottomFadingStrength: Float? = null
var leftFadingStrength: Float? = null
var rightFadingStrength: Float? = null
override fun getTopFadingEdgeStrength(): Float {
return topFadingStrength ?: super.getTopFadingEdgeStrength()
}
override fun getBottomFadingEdgeStrength(): Float {
return bottomFadingStrength ?: super.getBottomFadingEdgeStrength()
}
override fun getLeftFadingEdgeStrength(): Float {
return leftFadingStrength ?: super.getLeftFadingEdgeStrength()
}
override fun getRightFadingEdgeStrength(): Float {
return rightFadingStrength ?: super.getRightFadingEdgeStrength()
}
fun disableTopFade() {
topFadingStrength = 0f
}
fun disableBottomFade() {
bottomFadingStrength = 0f
}
fun disableLeftFade() {
leftFadingStrength = 0f
}
fun disableRightFade() {
rightFadingStrength = 0f
}
}