Code example for View

Methods: getLeft, getWidth

0
        if (mIconSelector != null) {
            removeCallbacks(mIconSelector);
        } 
        mIconSelector = new Runnable() {
            public void run() { 
                final int scrollPos = iconView.getLeft() - (getWidth() - iconView.getWidth()) / 2;
                smoothScrollTo(scrollPos, 0);
                mIconSelector = null;
            } 
        }; 
        post(mIconSelector);
    } 
 
    @Override 
    public void onAttachedToWindow() { 
        super.onAttachedToWindow(); 
        if (mIconSelector != null) {
            // Re-post the selector we saved 
            post(mIconSelector);
        } 
    }