2017-06-10 1 views
-1

J'ai ajouté quelques vues à l'intérieur de la barre d'outils, mais il y a un peu de rembourrage gauche que je veux supprimer.Supprimer l'espace gauche dans la barre d'outils android

enter image description here Je veux supprimer la section 'Supprimer cet espace.

Voici mon code 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" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.swornimlab.swornimlab.MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay" 
      > 
      <include 
       layout="@layout/layout_inside_toolbar" /> 
     </android.support.v7.widget.Toolbar> 

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

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

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

Voir que je veux ajouter dans la barre d'outils:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="?attr/actionBarSize"> 
    <LinearLayout 
     android:layout_weight="1" 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical" 
     > 
     <TextView 
      android:text="Hello, Asmin" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="10dp" 
      android:gravity="left" 
      android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large"/> 
     <TextView 
      android:text="Welcome Home" 
      android:layout_marginTop="10dp" 
      android:gravity="left" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"/> 
    </LinearLayout> 
    <ImageView 
     android:layout_weight="1" 
     android:src="@drawable/ic_home_vc" 
     android:tint="@android:color/white" 
     android:layout_alignParentRight="true" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/imageView2" /> 
</LinearLayout> 
+0

R u besoin bouton Hamburger – Raj

Répondre

0
android:layout_gravity="center_vertical" 

Cela semble être question.

Toujours sur une autre note, je vous suggère d'utiliser percentRelativelayout pour votre distribution de mise en page. Utiliser le poids avec votre disposition linéaire est très cher

+0

J'ai changé de disposition relative, mais n'a pas fonctionné. Je pense que c'est à cause de l'icône de navigation –

1

Enlever android:layout_gravity="center_vertical" de la disposition.

Toolbar:

Pour supprimer ajouter de l'espace gauche app:contentInsetStart
Pour supprimer l'espace droit ajouter app:contentInsetEnd

<android.support.v7.widget.Toolbar 
         android:id="@+id/toolbar" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:background="?attr/colorPrimary" 
         app:popupTheme="@style/AppTheme.PopupOverlay" 
         app:contentInsetEnd="0dp" 
         app:contentInsetStart="0dp"> 

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

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

layout_inside_toolbar.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="?attr/actionBarSize"> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <TextView 
      android:text="Hello, Asmin" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="10dp" 
      android:gravity="left" 
      android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large"/> 
     <TextView 
      android:text="Welcome Home" 
      android:layout_marginTop="10dp" 
      android:gravity="left" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"/> 
    </LinearLayout> 
    <ImageView 
     android:layout_weight="1" 
     android:src="@drawable/ic_home_vc" 
     android:tint="@android:color/white" 
     android:layout_alignParentRight="true" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/imageView2" /> 
</LinearLayout> 
+0

J'ai fait ce que vous avez dit mais ça ne fonctionne pas –

+0

supprimer aussi Android: layout_weight = "1" – Nikunj

+0

Je pense que c'est à cause de l'icône du menu de navigation –

0

enter image description here essayez ceci.

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
> 

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay"> 

     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="?attr/actionBarSize" 
      android:orientation="horizontal"> 

      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_gravity="center_vertical" 
       android:layout_weight="1" 
       android:orientation="vertical"> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="10dp" 
        android:gravity="left" 
        android:text="Hello, Asmin" 
        android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="10dp" 
        android:gravity="left" 
        android:text="Welcome Home" 
        android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium" /> 
      </LinearLayout> 

      <ImageView 
       android:id="@+id/imageView2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentRight="true" 
       android:layout_centerVertical="true" 
       android:layout_weight="1" 
       android:src="@drawable/ic_home_white_24dp" 
       android:tint="@android:color/white" /> 
     </RelativeLayout> 
    </android.support.v7.widget.Toolbar> 

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

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