2016-01-22 24 views
1

我做了一個XML其中包括具有下面的代碼textAlignement:center一個TextViewtextAlignement中心不工作的豆形軟糖

<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不運行textAlignement。

爲什麼它不能在jelylbean上工作,我該如何解決這個問題?

+0

利用重力更多信息http://developer.android.com/reference/android/widget/TextView.html# attr_android%3agravity – Madhur

+0

但我的TextView的重力已經居中,我試圖刪除alignement,它不會改變任何東西 – 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>