mercredi 20 mai 2015

Android HorizontalScrollView scrolls itself after animation

I have a HorizontalScrollView in my activity. There are 3 custom layouts in that scrollview which are added with addView method in code. My HorizontalScrollView is a subclass of HorizontalScrollView class. In that class, onScrollChanged method is overriden to log scrollChanging values.

@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
    Log.i("onScrollChanged", "l: " + l + " oldl: " + oldl + " t: " + t + " oldt: " + oldt);
    super.onScrollChanged(l, t, oldl, oldt);
}

This horizontal scroll view has a static height. That is 70dp. However, when one of the three views in the scrollview is clicked, scrollview's height changes to 200dp. When clicked again, it comes back to 70dp. There is a height changing animation on onClick event.

I added animation listeners to these expand/collapse animations. HorizontalScrollView's scrollX value changes after animation ends. Even if I set the scrollX in the "onAnimationEnd" method, horizontal scroll view's onScrollChanged method is called again and scrollview scrolls with large offsets which I can not find any reasonable clue to detect why it is happening.

I thought that this could be about animation and height change of horizontal scrollview.

Aucun commentaire:

Enregistrer un commentaire