文本视图的文本不会对齐中心,因为Android中文本的字符数增加了?
我让文本视图对齐图像视图的底部-中心。当我有一个较少的字符,它将显示正确对齐图像视图的中心,如图所示 但若我有更多的字符,它将不会像下图所示的那个样对齐图像视图的中心 我想对齐文本中心,即使它包含更多字符。我在下面添加了我的代码文本视图的文本不会对齐中心,因为Android中文本的字符数增加了?,android,Android,我让文本视图对齐图像视图的底部-中心。当我有一个较少的字符,它将显示正确对齐图像视图的中心,如图所示 但若我有更多的字符,它将不会像下图所示的那个样对齐图像视图的中心 我想对齐文本中心,即使它包含更多字符。我在下面添加了我的代码 <RelativeLayout android:id="@+id/content" android:layout_width="match_parent" android:layout_height="match_parent" a
<RelativeLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp" >
<ImageView
android:id="@+id/meme"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:scaleType="fitXY"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/bottom_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="BOTTOM TEXT"
android:textColor="@android:color/white"
android:textSize="25dp" />
</RelativeLayout>
使用下面的代码:它包含安卓:gravity=“center”,将视图中的文本作为中心。没问题有多少字
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp" >
<ImageView
android:id="@+id/meme"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:scaleType="fitXY"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/bottom_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:layout_centerHorizontal="true"
android:text="BOTTOM TEXT BOTTOM TEXT BOTTOM TEXT"
android:textColor="@android:color/white"
android:textSize="25dp" />
</RelativeLayout>
其中规定:
指定当文字小于视图时,如何按视图的x轴和/或y轴对齐文字。您可以参考android:gravity=“center”在文本视图中添加这一行。