This will be associated with some calculations.
Basically you need to scroll to a position to center the element.
int scrollX = (button.getLeft() - (screenWidth/2))+(button.getWidth()/2); hScrollView.scrollTo(scrollX,0);
Where
button -> It is the button you are trying to center. screenWidth -> Width of the screen. int screenWidth = getWindowManager().getDefaultDisplay().getWidth(); hScrollView -> It is the horizontal scrollview.
But even with this method, you will not be able to center the final elements, since scrollviews will not go beyond it.
source share