Scroll to last line of TableLayout within a ScrollView

前端 未结 2 1517
悲&欢浪女
悲&欢浪女 2021-01-02 01:34

I want to have a dynamic table, with rows added over time as a result of user interaction, using a TableLayout inside a ScrollView. This works fine, but when I want to scrol

2条回答
  •  借酒劲吻你
    2021-01-02 02:12

    Finding the hint above useful, here is a simple implementation that scrolls a ScrollView to make a given child visible...

    a: Prepare the following helper class

    public class ScrollToTrick implements Runnable {
    
    ScrollView scroller;
    View       child;
    
    ScrollToTrick(ScrollView scroller, View child) {
        this.scroller=scroller; 
        this.child=child;
    
    }
    public void run() {
        scroller.scrollTo(0, child.getTop());
    }
    }
    

    b) call it like this

    my_scroller.post(new ScrollToTrick(my_scroller,child_to_scroll_to) );
    

提交回复
热议问题