我制作了一个XML,它包含一个TextView在下面的代码中有一个textAlignement:center

<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不运行textalignment。
为什么它不起作用,我怎么能解决这个问题?

最佳答案

  <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"/>

android:gravitysubviews内部设置内容的重力。
container设置相对的
致其父android:layout_gravityView/Layout的所有内容都定义了影响外部元素的内容。

10-02 09:23