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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

1111. appearing after print sequence - php -