Search in sources :

Example 51 with OnGlobalLayoutListener

use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project KitKatEmoji by crossle.

the class PagerSlidingTabStrip method notifyDataSetChanged.

public void notifyDataSetChanged() {
    tabsContainer.removeAllViews();
    tabCount = pager.getAdapter().getCount();
    for (int i = 0; i < tabCount; i++) {
        if (pager.getAdapter() instanceof IconTabProvider) {
            addIconTab(i, ((IconTabProvider) pager.getAdapter()).getPageIconResId(i));
        } else {
            addTextTab(i, pager.getAdapter().getPageTitle(i).toString());
        }
    }
    updateTabStyles();
    getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @SuppressWarnings("deprecation")
        @SuppressLint("NewApi")
        @Override
        public void onGlobalLayout() {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                getViewTreeObserver().removeGlobalOnLayoutListener(this);
            } else {
                getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
            currentPosition = pager.getCurrentItem();
            scrollToChild(currentPosition, 0);
        }
    });
}
Also used : OnGlobalLayoutListener(android.view.ViewTreeObserver.OnGlobalLayoutListener) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Aggregations

OnGlobalLayoutListener (android.view.ViewTreeObserver.OnGlobalLayoutListener)51 ViewTreeObserver (android.view.ViewTreeObserver)25 SuppressLint (android.annotation.SuppressLint)18 View (android.view.View)13 Paint (android.graphics.Paint)12 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)8 TypedArray (android.content.res.TypedArray)7 DisplayMetrics (android.util.DisplayMetrics)7 RectF (android.graphics.RectF)6 TextView (android.widget.TextView)6 AbsListView (android.widget.AbsListView)4 ListView (android.widget.ListView)4 Scroller (android.widget.Scroller)4 Animator (android.animation.Animator)3 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)3 AnimatorSet (android.animation.AnimatorSet)3 ObjectAnimator (android.animation.ObjectAnimator)3 ValueAnimator (android.animation.ValueAnimator)3 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)3 AppWidgetHostView (android.appwidget.AppWidgetHostView)3