我正在尝试对齐文本,就像您希望看到的那样,如果您在写字板中并将对齐方式设置为居中,则每行的中间将位于屏幕的中心,而每个边距将位于屏幕的中心等距。但是,使用重力似乎无效,因为文本仍从左侧开始。有人能解释为什么吗?这是xml。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:orientation="vertical"
android:background="#111111"
tools:context="eqlogic.annswingsandthings.AboutUs">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/chalkBoard"
android:src="@drawable/ann_chalkboard_img"
android:layout_weight="0.5"/>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:id="@+id/scrollView"
android:layout_gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:textColor="#999999"
android:text="@string/AboutUsText"
android:textSize="24sp"
android:id="@+id/textView"
android:layout_gravity="center_horizontal"
android:singleLine="false" />
</ScrollView>
</LinearLayout>
您没有设置重力,请使用:
android:gravity="center"
完整标签:
<TextView
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:textColor="#999999"
android:text="@string/AboutUsText"
android:textSize="24sp"
android:id="@+id/textView"
android:layout_gravity="center_horizontal"
android:singleLine="false" />
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句