[英]Text of Text View will not align center due to increase in characters of Text in Android?
我的文本視圖底部對齊-圖像視圖的中心 。 當我的字符較少時,它將正確顯示圖像視圖的對齊中心,如圖所示。
但是,如果我有更多沒有。 的字符將無法與圖像視圖的中心對齊,如下面的圖片所示
我想對齊文本中心,即使它包含更多字符。 我在下面添加了我的代碼。
<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>
在下面的代碼中使用:包含android: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軸對齊文本。 你可以在這里參考
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.