NestedScrollView's smoothScrollTo() behaves weird

后端 未结 4 1228
半阙折子戏
半阙折子戏 2020-12-04 03:09

What I am trying to achieve is to scroll to scroll_position_1 when tab1 (and so on) is clicked like this. I don\'t understand what\'s happening at

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-04 03:56

    You can use a ListView instead of a ConstraintLayout and add the text views to the list. Then, you can simply call listView.smoothScrollToPosition(index) instead of worrying about the x and y coordinates.

    1) Edit your layout as shown below.

    2) Add items to your ListView via code.

    3) Upon tab click, call listView.smoothScrollToPosition(index_of_text_view) and your list view scrolls to that position.

    
    
    
    
    
          
    
            
    
              
    
                  
    
                  
              
    
              
           
    
    
    
        
    
            
    
            
        
    
    

提交回复
热议问题