Frage

I've made a vertical SeekBar by overriding the onDraw method and flipping it 90 degrees. Now I need to put this in a ScrollView.

The actual layout structure is

<ScrollView>
  <RelativeLayout>
     ...
     <LinearLayout>
       <com.mypackage.VerticalSeekBar/>

Is it possible to make sure the ScrollView does not get the touch event of my seekbar?

War es hilfreich?

Lösung

Try this :

ListView lv = (ListView)findViewById(R.id.myListView);  // your listview inside scrollview

    lv.setOnTouchListener(new ListView.OnTouchListener() 
    {
        @Override
        public boolean onTouch(View v, MotionEvent event) 
        {
            int action = event.getAction();
            switch (action) 
            {
            case MotionEvent.ACTION_DOWN:
                // Disallow ScrollView to intercept touch events.
                v.getParent().requestDisallowInterceptTouchEvent(true);
                break;

            case MotionEvent.ACTION_UP:
                // Allow ScrollView to intercept touch events.
                v.getParent().requestDisallowInterceptTouchEvent(false);
                break;
            }

            // Handle ListView touch events.
            v.onTouchEvent(event);
            return true;
        }
    });

In above code I have used listview scroll inside scrollview you can you approach like this

Andere Tipps

Try this approach

<ScrollView  
focusable="false" 
focusableInTouchMode="false" >

And in

<LinearLayout or in VerticalSeekBar
focusable="true" 
focusableInTouchMode="true" >

It will stop ScrollView from getting focus and focus is get by VerticalSeekbar.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top