我有以下布局,我想让 textview 出现在 View 的中心和中间。我怎样才能做到这一点?
在图形 View 中查看布局时,我尝试调整各种重力属性,但似乎没有任何改变。我想要中间的 TextView ,我已经完成了,但在 View 的一半。
感谢马特。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/carefreebgscaledalphajpg" >
<TextView
android:id="@+id/textviewdatefornocallspage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="You have no calls for "
android:textSize="25sp" />
</LinearLayout>
最佳答案
在你的linearLayout标签中将重力设置为中心:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:background="@drawable/carefreebgscaledalphajpg" >
或像这样使用 RelativeLayout
:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/carefreebgscaledalphajpg" >
<TextView
android:id="@+id/textviewdatefornocallspage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="You have no calls for "
android:textSize="25sp" />
</RelativeLayout>
关于android - 如何在线性布局中居中 TextView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13474982/