水平对齐 textView 居中
Align textView center horizontally
我希望控制器 textView 成为应用程序的中心。我使用 android:gravity="center" 但没有帮助。
我的密码是
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CONTROLLER"
android:textSize="30dp"
android:gravity="center"
android:textColor="#fff"
android:layout_marginTop="39dp"
android:id="@+id/textView3"
/>
</LinearLayout>
在此先感谢您的帮助。
只需android:gravity="center"
在Layout中,android:layout_height="match_parent"
在整个View中将TextView居中。
和 android:gravity="center_horizontal" to centralize it horizontaly.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CONTROLLER"
android:textSize="30sp"
android:textColor="#fff"
android:layout_marginTop="39dp"
android:id="@+id/textView3"
/>
</LinearLayout>
而且 textSize 应该在 sp 而不是 dp 中测量。
我希望控制器 textView 成为应用程序的中心。我使用 android:gravity="center" 但没有帮助。 我的密码是
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CONTROLLER"
android:textSize="30dp"
android:gravity="center"
android:textColor="#fff"
android:layout_marginTop="39dp"
android:id="@+id/textView3"
/>
</LinearLayout>
在此先感谢您的帮助。
只需android:gravity="center"
在Layout中,android:layout_height="match_parent"
在整个View中将TextView居中。
和 android:gravity="center_horizontal" to centralize it horizontaly.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CONTROLLER"
android:textSize="30sp"
android:textColor="#fff"
android:layout_marginTop="39dp"
android:id="@+id/textView3"
/>
</LinearLayout>
而且 textSize 应该在 sp 而不是 dp 中测量。