Question

I create my own class which extend ScrollView but scroll bar disapear. How Can I show scroll bar when I scroll page. This is code my class:

package se.nindev.restaurant.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ScrollView;

public class ScrollViewer extends ScrollView {
    private float mLastX;
    private float mLastY;
    private float mDiffX;
    private float mDiffY;

         public ScrollViewer(Context context) {
          this(context, null);
         }

         public ScrollViewer(Context context, AttributeSet attrs) {
          this(context, attrs, 0);
         }
         public ScrollViewer(Context context, AttributeSet attrs, int defStyle) {
          super(context, attrs, defStyle);
         }

//       @Override
//       public boolean dispatchTouchEvent(MotionEvent ev){
//           return super.dispatchTouchEvent(ev);
//       } 
         @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
             switch (ev.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    // reset difference values
                    mDiffX = 0;
                    mDiffY = 0;

                    mLastX = ev.getX();
                    mLastY = ev.getY();
                    break;

                case MotionEvent.ACTION_MOVE:
                    final float curX = ev.getX();
                    final float curY = ev.getY();
                    mDiffX += Math.abs(curX - mLastX);
                    mDiffY += Math.abs(curY - mLastY);
                    mLastX = curX;
                    mLastY = curY;

                    // don't intercept event, when user tries to scroll horizontally
                    if (mDiffX > mDiffY) {
                        return false;
                    }
             }
        return super.onInterceptTouchEvent(ev);
        }
}

More over others elements disaper like when I scroll in the middle of page in scrollview has grafic effects in the top end bottom of page, but in the my class I haven't that effects. How can I add all effects from normal scroll view to my class?

Edit: ok I add scroll bar: android:scrollbars="vertical" but still don't know how add this grafic effects

Was it helpful?

Solution

 ScrollView scrollView = new ScrollView(getContext());
 scrollView.setVerticalScrollBarEnabled(true);
 scrollView.setHorizontalScrollBarEnabled(true);

OTHER TIPS

android:background="@color/white"
android:fadingEdge="vertical"

we need change background scrollview on white and use fading edge

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top