scrollTo, scrollBy, smoothScrollTo, smoothScrollTo don't work in ScrollView after adding view in child layout

非 Y 不嫁゛ 提交于 2019-12-04 11:40:41

问题


I have HorizontalScrollView with child Layout inside. After adding view into child layout I can't scroll HorizontalScrollView to the right side of scroller.

scrollTo, scrollBy, smoothScrollTo, smoothScrollTo don't work.


回答1:


solved:

LinearLayout ll = (LinearLayout) findViewById(R.id.ll);

        final HorizontalScrollView hsv = (HorizontalScrollView) findViewById(R.id.hsv);
        OnGlobalLayoutListener listener = new OnGlobalLayoutListener() {

            @Override
            public void onGlobalLayout() {
                hsv.scrollTo(100, 0);
            }
        };
        ll.getViewTreeObserver().addOnGlobalLayoutListener(listener);


来源:https://stackoverflow.com/questions/6696793/scrollto-scrollby-smoothscrollto-smoothscrollto-dont-work-in-scrollview-afte

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!