2017-02-22 2 views
1

the logo cannot align to the left drawer icon Die Symbolleiste Layout ausrichten I gesetzt android: layout_gravity = "center_vertical" aber es funktioniert nichtAndroid die Navigationsleiste Symbol und Logo kann nicht

Code:

<?xml version="1.0" encoding="utf-8"?> 
    <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="100dp" 
    android:background="@drawable/toolbar_bg" 
    android:fitsSystemWindows="true" 
    app:popupTheme="@style/Theme.AppCompat.Light.DarkActionBar" 
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_vertical" 
    android:src="@android:drawable/sym_def_app_icon" /> 

Haupt Layout:

<!-- As the main content view, the view below consumes the entire 
    space available using match_parent in both dimensions. --> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <include 
     android:id="@+id/head_tool_bar" 
     layout="@layout/toolbar" /> 

    <FrameLayout 
     android:id="@+id/container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/head_tool_bar" /> 

</RelativeLayout> 
<!-- The drawer is given a fixed width in dp and extends the full height of 
    the container. --> 
<fragment 
    android:id="@+id/navigation_drawer" 
    android:name="com.voogolf.helper.home.NavigationDrawerFragment" 
    android:layout_width="@dimen/navigation_drawer_width" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    tools:layout="@layout/drawer_new_home" /> 

</android.support.v4.widget.DrawerLayout> 

Wie kann ich Schubladensymbol und Logo oben ausrichten? Warum links Schublade Symbol Padding haben so?

+0

Was ist das Bild in diesem Bild? –

+0

Es ist besser, wenn Sie diese Elemente in einem relativen oder linearen Layout in der Symbolleiste hinzufügen. –

+0

Ich entferne meine benutzerdefinierte Bildansicht in der Symbolleiste und toolbar.setLogo(), aber das Ergebnis ist das gleiche wie das obige Bild, kann nicht die linke Schublade Symbol Algin, warum? –

Antwort

0

diese Eigenschaft Attribut hinzufügen Imageview android:layout_gravity="center_vertical"

+0

Ich mache es, aber arbeite nicht –

+0

Sie können Ihre Text- und Bildansichten innerhalb eines linearen Layouts umhüllen und versuchen, seine Schwerkraft zu setzen – Mohamed

0

sollten Sie versuchen, das Layout der Schwerkraft wie diese Einstellung.

android:layout_gravity="left|center_vertical" 

und stellen Sie sicher, padding und margin ist 0dp

0

wenn Sie versuchen, Ihre toolbar dann tun, so etwas zu gestalten.

<?xml version="1.0" encoding="utf-8"?> 
    <android.support.v7.widget.Toolbar 
    ...> 
<RelativeLayout> 
<ImageView 
    ... /> 
//here you can add more view items 
</RelativeLayout> 
</android.support.v7.widget.Toolbar> 

wenn Sie Toolbar verwendet haben und die Aktionsleiste Einrichtung mit ActionBarDrawerToggle dann diesen Code auf Ihre ActionBarDrawerToggle Objekt hinzuzufügen.

toggle.setDrawerIndicatorEnabled(false);  // this will disable your default haburger icon 
toggle.setHomeAsUpIndicator(R.drawable.ic_custom_drawer_icon); // this will replace the toggle home indicator 
+0

Wenn ich Symbolleiste anpassen, wie ein ImageView links anstelle der linken Schublade Symbol festlegen und an DrawerToggle binden. –

+0

Wenn Sie versuchen, das Symbol für den Wechsel der Schublade zu ersetzen, ist das etwas anderes. Dafür müssen Sie programmieren. Sie müssen keine Bildansicht hinzufügen. Wird dies in einiger Zeit aktualisieren. –

0

Android-Support v7-Symbolleiste ist genau wie andere Ansichten. Sie können die Ansicht, die Sie benötigen, in der Symbolleiste anpassen oder hinzufügen. Ihre imageView sollte innerhalb der toolbar und machen imageView ausgerichtet, was Sie wollen, durch gravity or layout_gravity Attribut.

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal"> 
    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/home_button" 
     android:background="@color/colorToolbarWelcomeBg" 
     android:scaleType="fitCenter" 
     android:src="@drawable/back_arrow" 
     android:layout_gravity="left|centre"/> 
    <TextView 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="0.6" 
     android:background="@color/colorToolbarWelcomeBg" 
     android:text="Settings" 
     android:textColor="@color/colorWhite" 
     android:textStyle="bold" 
     android:id="@+id/welcomeToManager" 
     android:gravity="center"/> 
</LinearLayout> 

und legen dieses Layout innerhalb <toolbar> Above layout </toolbr> Dieser Code zeigt nur eine Idee nicht unbedingt Code :)

+0

wie man home_button animation einstellt Schublade wie toggle icon animation öffnen –

0

Dies ist meine Symbolleiste mit einem Back-Button und Text in center.You diesen Code verweisen.

 <?xml version="1.0" encoding="utf-8"?> 
     <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="?attr/colorPrimary" 
      android:contentInsetLeft="0dp" 
      android:contentInsetStart="0dp" 

      android:minHeight="?attr/actionBarSize" 
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
      app:contentInsetLeft="0dp" 
      app:contentInsetStart="0dp" 
      app:contentInsetStartWithNavigation="0dp" 
      app:layout_collapseMode="pin" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light"> 

      <FrameLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

       <ImageView 
        android:id="@+id/back_arrow" 
        android:layout_width="25dp" 
        android:layout_height="25dp" 
        android:layout_gravity="left|center" 
        android:visibility="visible" 
        android:layout_marginLeft="8dp" 
        android:layout_marginRight="8dp" 
        android:src="@drawable/back_arrow" /> 


       <com.indosat.rider.views.CustomTextView 
        android:id="@+id/toolbar_custom_title" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:gravity="center" 
        android:text="Register Page" 
        style="@style/roboto_medium" 
        android:textAllCaps="true" 
        android:textColor="@color/white" 
        android:textSize="19sp" /> 



      </FrameLayout> 


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

Lassen Sie mich wissen, wenn Sie Hilfe bei der Einrichtung Ihrer endgültigen Einrichtung benötigen.

Verwandte Themen