Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 737
mobiledev Alex Avatar asked Jul 14 '11 16:07

mobiledev Alex


People also ask

How to implement scroll view in android?

In order to place multiple views in the scroll view, one needs to make a view group(like LinearLayout) as a direct child and then we can define many views inside it. A ScrollView supports Vertical scrolling only, so in order to create a horizontally scrollable view, HorizontalScrollView is used.


1 Answers

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);
like image 100
mobiledev Alex Avatar answered Oct 04 '22 23:10

mobiledev Alex