Android: HorizontalScrollView inside ScrollView

前端 未结 6 1956
忘掉有多难
忘掉有多难 2021-02-05 12:46

I have multiple HorizontalScrollViews inside a ScrollView. Horizontal scroll isn\'t smooth at all. I have to scroll almost perfectly horizontal

6条回答
  •  面向向阳花
    2021-02-05 13:16

    This class creates a ScrollView containing a HorizontalScrollView combined into one class. You can put stuff inside it using the AddChild() method. The dispatchTouchEvent overide keeps the scrolling smooth so you can pan around with a single slide of the finger.

    (I recently used this to wrap a programmatically created TextView)

    class MultiScrollView extends ScrollView
    {           
     public HorizontalScrollView hscroll;
    
     public MultiScrollView ( Context context ) 
     { 
       super( context );
     }
    
     public void AddChild( View child ) 
     {                                              
       hscroll.addView( child );
     }
    
     @Override
     public boolean dispatchTouchEvent( MotionEvent event ) 
     {
       hscroll.dispatchTouchEvent(event);
       onTouchEvent(event);
       return true;
     }
    }
    

提交回复
热议问题