Center position of logo in Action Bar Android -


i want display logo @ centre of action bar. here's custom layout code:

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/actionbarwrapper"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_gravity="center"     android:orientation="horizontal"     >      <imageview         android:id="@+id/icon"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:src="@drawable/logo"         android:layout_centerinparent="true"         android:padding="8dp"/>    </relativelayout> 

and in oncreate() i'm using as:

getsupportactionbar().setdisplayoptions(actionbar.display_show_custom);         getsupportactionbar().setcustomview(r.layout.custom_logo);         getsupportactionbar().setbackgrounddrawable(new colordrawable(color.parsecolor("#2a2a2a"))); 

the issue displays fine in normal fragments , activity shifts little right when used navigation drawer. here images:

  1. wrong one: wrong display
  2. right one: right display

what doing wrong? thanks.

try using linear layout , layout_gravity :

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"         android:id="@+id/actionbarwrapper"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:orientation="vertical">          <imageview             android:id="@+id/icon"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:src="@drawable/logo"             android:layout_gravity="center"             android:padding="8dp"/>      </linearlayout> 

hope help


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -