Search code examples
androidscrollview

Android: Remove only bottom FadingEdge effect from scroll bar


I know how to disable fadingedge from scrollbar but what I need is to disable just the bottom fading edge without disabling the top fading edge effect, is that possible?


Solution

  • You can achieve the effect you want by extending the ScrollView and overriding one of those two methods:

    float getTopFadingEdgeStrength()
    float getBottomFadingEdgeStrength()
    

    They'll alow you to change the size of the fading edge - just set bottom value to 0 and you are ready to go :)

    Code example with bottom fading turned off:

    /**
     * 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;
        }
    }