我制作了一个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:gravity
在subviews
内部设置内容的重力。container
设置相对的致其父
android:layout_gravity
。View/Layout
的所有内容都定义了影响外部元素的内容。