[英]Alignment issue for TextView
I am displaying the TextView
within a RelativeLayout
. 我在RelativeLayout
显示TextView
。
I want to put the TextView
at the center of the Layout. 我想将TextView
放在布局的中心。
Within the layout xml, for TextView
am using the property android:gravity="center"
is not working . 在布局xml中,对于TextView
我无法使用android:gravity="center"
属性。
I do not want to hard code by using android:layout_marginLeft
or Right since it can give different effect in portrait or landscape mode. 我不想使用android:layout_marginLeft
或Right进行硬编码,因为它可以在纵向或横向模式下产生不同的效果。
Is there property so that it looks the same for both landscape & portrait mode & the TextView
occupies the center of the Layout 是否存在属性,因此横向和纵向模式下的外观都相同,并且TextView
占据布局的中心
Since RelativeLayout
is your TextView
's parent, you simply set android:layout_centerInParent="true"
on your TextView
. 由于RelativeLayout
是TextView
的父级,因此您只需在TextView
上设置android:layout_centerInParent="true"
。 No other properties are needed. 不需要其他属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.