I asked a similar question here... I got some tutorials in the answers. But this question is diffrenet. because none of that method do not works in my project.
I want
you can do it programmatically as follows:
mToolbar.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
ImageView imageView = (ImageView)mToolbar.findViewById(R.id.logo);
if( mToolbar == null ){
return;
}
int toolbarWidth = mToolbar.getWidth();
int imageWidth = imageView.getWidth();
imageView.setX((toolbarWidth-imageWidth)/2);
}
});
customise your layout_toolbar.xml: