2016-01-22 1 views
1

Я сделал XML, которые включают в себя TextView, имеющий в следующем коде в textAlignement:center:textAlignement центр не работает на Jellybean

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="1"> 
     <Button 
      android:layout_width="0px" 
      android:layout_weight="0.24" 
      android:text="gestion" 
      android:layout_height="wrap_content" 
      android:id="@+id/GoGestion"/> 

     <View 
      android:layout_width="0px" 
      android:layout_weight="0.01" 
      android:layout_height="match_parent"></View> 
    <TextView 
     android:layout_width="0px" 
     android:layout_weight="0.5" 
     android:layout_height="wrap_content" 
     android:text="Creation Sav" 
     android:textSize="40dp" 
     android:layout_gravity="center" 
     android:textAlignment="center"/> 

     <View 
      android:layout_width="0px" 
      android:layout_weight="0.01" 
      android:layout_height="match_parent"></View> 
    <Button 
      android:layout_width="0px" 
      android:layout_weight="0.24" 
      android:text="Archive" 
      android:layout_height="wrap_content" 
      android:id="@+id/GoArchive"/> 
    </LinearLayout> 

И дело в том, что мой TextView не центрирован на таблетку, имеющую 4.1 .2 (jellybean), но находится на другой планке 4.4.2 (kitkat).
Мое приложение составляет minSdkVersion 15, поэтому jellybean является более поздним. Нигде в документе не указано, что Jellybean не запускает textAlignement.

Почему это не работает на jelylbean и как я могу это исправить?

+0

использовать гравитацию для получения дополнительной информации http://developer.android.com/reference/android/widget/TextView.html# attr_android% 3agravity – Madhur

+0

, но гравитация моего TextView уже слишком центра, я попытался удалить выравнивание, и он ничего не меняет – RiddlerNewComer

+1

чувак не layout_gravity вам нужно установить android: gravity = "center" – Madhur

ответ

1
<TextView 
     android:layout_width="0px" 
     android:layout_weight="0.5" 
     android:layout_height="wrap_content" 
     android:text="Creation Sav" 
     android:textSize="40dp" 
     android:layout_gravity="center" 
     android:textAlignment="center"/> 

изменение

<TextView 
     android:layout_width="0px" 
     android:layout_weight="0.5" 
     android:layout_height="wrap_content" 
     android:text="Creation Sav" 
     android:textSize="40dp" 
     android:gravity="center" 
     android:textAlignment="center"/> 
4

Вы можете установить это в TextView

android:gravity="center" 

Поместите объект в центре контейнера в обоих вертикальной и горизонтальной оси, не изменяя его размер.

Пожалуйста, проверьте Gravity and layout_gravity on Android. Надеюсь это поможет .

0

Поместите этот код

<?xml version="1.0" encoding="utf-8"?> 


    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="1"> 

     <Button 
      android:id="@+id/GoGestion" 
      android:layout_width="0px" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.24" 
      android:text="gestion" /> 

     <View 
      android:layout_width="0px" 
      android:layout_height="match_parent" 
      android:layout_weight="0.01"></View> 

     <TextView 
      android:layout_width="0px" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_weight="0.5" 
      android:text="Creation Sav" 
      android:gravity="center" 
      android:textAlignment="center" 
      android:textSize="40dp" /> 

     <View 
      android:layout_width="0px" 
      android:layout_height="match_parent" 
      android:layout_weight="0.01"></View> 

     <Button 
      android:id="@+id/GoArchive" 
      android:layout_width="0px" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.24" 
      android:text="Archive" /> 
    </LinearLayout> 
Смежные вопросы