Forum Xamarin.Android

Centering ImageView in SupportActionBar when action buttons are present.


I would like to center the ImageView within the screen not within the relative layout that is in right now.

I have tried:

But non of the solutions worked for me.

One thing that I was not able to do was:

View homeButton = findViewById( );
final ViewGroup holder = (ViewGroup) homeButton.getParent();

Although I am able to translate this in C# it still returns null when getting the home button.

When I am creating the action buttons I do this in:

public override bool OnCreateOptionsMenu (IMenu menu)

and I programatically add the buttons.

The logo part is being setup like this:

SupportActionBar.SetCustomView (Resource.Layout.support_action_bar);
SupportActionBar.SetDisplayShowCustomEnabled (true);

How can I add padding or margin to the image view to center it within the screen when the buttons are present? Also the count of the buttons might change in the application so this needs to be done programatically.

I thought that one way could be getting the size of the action buttons and adding that as a padding to the ImageView but I am unable to find a way how to do it.

Cheers for any help on this


  • JakubHolovskyJakubHolovsky CZMember

    I ended up replacing actionbar with Toolbar which gave me more flexibility and overall made modifications much easier.

Sign In or Register to comment.