Scroll to last line of TableLayout within a ScrollView

前端 未结 2 1516
悲&欢浪女
悲&欢浪女 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) );
    
    0 讨论(0)
  • 2021-01-02 02:24

    At the time you are doing your fullScroll() the layout has not happened yet, so the ScrollView uses the "old" size for the table. Instead of calling fullScroll() right away, use View.post(Runnable).

    0 讨论(0)
提交回复
热议问题