6

i need to implement following scenario,

here i have two horizontalScrollViews the upper scrollView is a main menu and lower scrollView is a submenu.

when i scroll main menu,the menu which comes under center arrow will show its submenu in lower scrollview and from the lower scrollview, the submenu which comes under center arrow shows the screen for that sub-menu.

here's my requirement:enter image description here

i've implemented it using HorizontalScrollViews and ViewFlipper and also it works but it will give correct result only when i scroll it slowly and not when scroll fast.

i've used onTouch() method with a ACTION_UP event,so when i release finger from screen it will gives me getScrollX() position at that point but here i need getScrollX() position when scroll is finished/stop.

here's my code:-

  @Override
    public boolean onTouch(View v, MotionEvent event) {
        switch (v.getId()) {

            case R.id.mHorizontalScrollViewMain:
           if (event.getAction() == KeyEvent.ACTION_UP) {
            Log.d("test", " " + hsvUpperTab.getScrollX() + " , "+ mViewFlipper.getChildCount());
            getUpperTabScrolled(hsvUpperTab.getScrollX());
        }
        break;

        case R.id.mHorizontalScrollViewSub:
                if (event.getAction() == KeyEvent.ACTION_UP) {
            Log.d("test1", " " + hsvLowerTab.getScrollX());
            getLowerTabScrolled(hsvLowerTab.getScrollX());

            }

        default:
            break;

        }

        return false;
    }
fasheikh
  • 419
  • 3
  • 19
NaserShaikh
  • 1,576
  • 2
  • 23
  • 39

3 Answers3

3

Here's my answer:

public class ScrollViewCustom extends HorizontalScrollView {
    private Runnable scrollerTask;
    private int intitPosition;
    private int newCheck = 100;
    private static final String TAG = "ScrollView";

    public interface onScrollStopListner{
        void onScrollStoped();
    }

    private onScrollStopListner onScrollstopListner;

    public ScrollViewCustom(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
            scrollerTask = new Runnable() {
                @Override
                public void run() {
                // TODO Auto-generated method stub
                    int newPosition = getScrollX();
                        if ( intitPosition - newPosition == 0 ) {
                            if ( onScrollstopListner != null ) {
                            onScrollstopListner.onScrollStoped();
                            }
                            }else{
                            intitPosition = getScrollX();
                            ScrollViewCustom.this.postDelayed(scrollerTask, newCheck);
                        }
                    }
        };
    }

    public void setOnScrollStopListner( ScrollViewCustom.onScrollStopListner listner ){
        onScrollstopListner = listner;
    }

    public void startScrollerTask(){
        intitPosition = getScrollX();
        ScrollViewCustom.this.postDelayed(scrollerTask, newCheck);
    }

}

Here's in Activity:

scroll.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
                        if ( event.getAction() == MotionEvent.ACTION_UP ) {
                            scroll.startScrollerTask();
                        }
                        return false;
            }
        });



        scroll.setOnScrollStopListner(new onScrollStopListner() {
                @Override
                public void onScrollStoped() {
                    // TODO Auto-generated method stub
                    Log.d(TAG," "+scroll.getScrollX());

                    }

        });
NaserShaikh
  • 1,576
  • 2
  • 23
  • 39
1

Here you go: Stackoverflow Answer

All you have to do is replace getScrollY() with getScrollX()

Community
  • 1
  • 1
Vic Vuci
  • 6,993
  • 6
  • 55
  • 90
0

We use following approach: create a custom HorizontalScrollView and override onScrollChanged(int l, int t, int oldl, int oldt) method and your code goes there. for more accurate we override draw method also.

Sudar Nimalan
  • 3,962
  • 2
  • 20
  • 28
  • i've also tried that but isn't that onSCrollChange() method gives current scrolling value? i need something which give me end of scroll value.i mean when scroll is finshed. i didn't use draw() method, i'll try this. – NaserShaikh Sep 03 '12 at 06:48