HorizontalScrollView: auto-scroll to end when new Views are added?

后端 未结 9 1197
鱼传尺愫
鱼传尺愫 2020-11-28 06:37

I have a HorizontalScrollView containing a LinearLayout. On screen I have a Button that will add new Views to the LinearLayout at runtime, and I\'d like the scroll view to

9条回答
  •  被撕碎了的回忆
    2020-11-28 07:06

    I think the best approach is the one posted by monxalo because you can not know how much time will it take until the layout is done. I tried it and it works perfectly. The only difference is, that I added only one row to my custom horizontal scroll view:

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        super.onLayout(changed, l, t, r, b);
        this.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
    }
    

提交回复
热议问题