2017-06-01 4 views
-2

Ich möchte Logo in der Mitte machen, aber es wird links & nicht in der Mitte für große Bildschirmauflösung Geräte gesetzt.Wie Logo in der Mitte in der Symbolleiste zu machen?

Unten ist mein xmls

activity_app_base.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    app:elevation="1dp"> 


    <include 
     layout="@layout/app_bar_app_base" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

</android.support.design.widget.CoordinatorLayout> 

app_bar_app_base.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    android:orientation="vertical"> 

    <include layout="@layout/new_header_toolbar_design"></include> 

    <include layout="@layout/content_app_base" /> 

</LinearLayout> 

new_header_toolbar_design.xml

<?xml version="1.0" encoding="utf-8"?> 
    <android.support.design.widget.AppBarLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:app="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="@color/white" 
      android:contentInsetStart="0dp" 
      app:theme="@style/MyToolbarStyle" 
      android:contentInsetLeft="0dp" 
      app:contentInsetLeft="0dp" 
      app:contentInsetStart="0dp" 
      android:contentInsetStartWithNavigation="0dp" 
      app:contentInsetStartWithNavigation="0dp"> 

      <RelativeLayout 
       android:id="@+id/rl_User_Profile" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

       <ImageView 
        android:id="@+id/imageView_User_Image" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentLeft="true" 
        android:layout_alignParentStart="true" 
        android:layout_centerVertical="true" 
        android:visibility="gone" 
        android:layout_margin="1dp" /> 
       <ImageView 
        android:id="@+id/imageView_APP_LOGO" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:visibility="invisible" 
        android:layout_alignRight="@+id/imageView_User_Image" 
        android:src="@drawable/header_logo" 
        android:layout_centerVertical="true" 
        android:layout_margin="1dp" /> 
       <ImageView 
        android:id="@+id/imageView_LOGO" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerHorizontal="true" 
        android:layout_centerVertical="true" 
        android:layout_alignTop="@+id/imageView_APP_LOGO" 
        android:layout_toRightOf="@+id/imageView_APP_LOGO" 
        android:layout_toLeftOf="@+id/imageView_Space" 
        android:layout_alignBottom="@+id/imageView_APP_LOGO" 
        android:paddingLeft="-65dp" 
        android:src="@drawable/header_logo" 
        /> 
       <ImageView 
        android:id="@+id/imageView_Space" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginEnd="10dp" 
        android:layout_marginRight="10dp" 
        android:layout_centerVertical="true" 
        android:layout_alignParentRight="true" 
        android:layout_alignParentEnd="true" 
        /> 



      </RelativeLayout> 


     </android.support.v7.widget.Toolbar> 

    </android.support.design.widget.AppBarLayout> 
+0

ich denke, das wird hilfreich für Sie sein .. https: // stackoverfl ow.com/questions/43735960/custom-component-toolbar-fragment-with-onoptionmenu-items –

+0

Veröffentlichen Sie einen Snap. Wie sieht es aus? – Wizard

Antwort

0

Verwenden android:layout_centerInParent="true" für Image und entfernen

   android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:layout_centerVertical="true" 
0

Logo in der Mitte auszurichten, verwende ich diesen Code in der entsprechenden Aktivität ..

Dieser Code Sie können

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 
     getSupportActionBar().setLogo(R.drawable.logo_title); 
     getSupportActionBar().setDisplayUseLogoEnabled(true); 
0

Verwendung Linear-Layout und Satz helfen Schwerkraft des linearen Layouts zu zentrieren

<?xml version="1.0" encoding="utf-8"?> 
      <android.support.design.widget.AppBarLayout 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:app="http://schemas.android.com/apk/res-auto" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:theme="@style/AppTheme.AppBarOverlay"> 

       <android.support.v7.widget.Toolbar 
        xmlns:android="http://schemas.android.com/apk/res/android" 
        xmlns:app="http://schemas.android.com/apk/res-auto" 
        android:id="@+id/toolbar" 
        android:layout_width="match_parent" 
        android:layout_height="?attr/actionBarSize" 
        android:background="@color/white" 
        android:contentInsetStart="0dp" 
        app:theme="@style/MyToolbarStyle" 
        android:contentInsetLeft="0dp" 
        app:contentInsetLeft="0dp" 
        app:contentInsetStart="0dp" 
        android:contentInsetStartWithNavigation="0dp" 
        app:contentInsetStartWithNavigation="0dp"> 

        <LinearLayout 
         android:id="@+id/rl_User_Profile" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:gravity="center" 
         android:orientation="horizontal"> 

        <!--Change the size of imageview as per your requirement--> 
         <ImageView 
          android:id="@+id/imageView_User_Image" 
          android:layout_width="30dp" 
          android:layout_height="30dp" 
          android:visibility="gone" 
          android:layout_margin="1dp" /> 
         <ImageView 
          android:id="@+id/imageView_APP_LOGO" 
          android:layout_width="30dp" 
          android:layout_height="30dp" 
          android:visibility="invisible" 
          android:src="@drawable/header_logo" 
          android:layout_margin="1dp" /> 
         <ImageView 
          android:id="@+id/imageView_LOGO" 
          android:layout_width="30dp" 
          android:layout_height="30dp" 
          android:src="@drawable/header_logo" 
          /> 
         <ImageView 
          android:id="@+id/imageView_Space" 
          android:layout_width="30dp" 
          android:layout_height="30dp" 
          /> 
        </LinearLayout> 

       </android.support.v7.widget.Toolbar> 

      </android.support.design.widget.AppBarLayout> 
Verwandte Themen