2017-06-06 3 views
-1

Je ceci est mon xml:Définir texte au centre de AppBar

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

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_height="57dp" 
     android:layout_width="match_parent"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:text="Ranger" 
      android:id="@+id/logoSign"/> 
    </android.support.design.widget.AppBarLayout> 
</RelativeLayout> 

Je veux faire le TextView dans le centre de la barre d'accès. Mais je reçois ceci: enter image description here

Merci pour votre aide. :)

Répondre

0

il suffit d'utiliser ce code pour textview

<TextView 
     android:layout_width="match_content" 
     android:layout_height="match_content" 
     android:layout_gravity="center" 
     android:gravity="center" 
     android:text="Ranger" 
     android:id="@+id/logoSign"/> 
+0

Merci beaucoup! tu as sauvé ma journée! :RÉ –

0

Essayez cette

<TextView 
     android:layout_width="wrap_content" 
     android:layout_height="match_content" 
     android:layout_gravity="center_horizontal|center_vertical" 
     android:text="Ranger" 
     android:id="@+id/logoSign"/> 
2

AppBar est en fait un Linearlayout. Essayez ceci:

<TextView 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="center" 
     android:gravity="center" 
     android:text="Ranger" 
     android:id="@+id/logoSign"/> 
1

Ce que vous pouvez faire est de prendre une RelativeLayout dans la AppBar avec la hauteur et la largeur « match_parent » et mettre le TextView à l'intérieur du RelativeLayout et le faire comme

android:layout_centerInParent="true" 

Espérons que cela aide.

1
<android.support.design.widget.AppBarLayout 
    android:id="@+id/appbar" 
    android:layout_height="57dp" 
    android:layout_width="match_parent"> 
    <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:gravity="center"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Ranger" 
      android:id="@+id/logoSign"/> 
    </LinearLayout> 
</android.support.design.widget.AppBarLayout>