Ads by ProfitSence
Close

Centro de alinhamento do Android TextView

Last Updated on Sábado 8º out 2022

Center Text Android Studio

			
					<TextView  
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center"
    android:text="@string/**yourtextstring**"
/>

			
	

Android TextView Center

  • Você também pode usar a gravidade center_vertical ou center_horizontal.
  • Se a altura e largura do TextView forem de conteúdo embrulhado, o texto dentro do TextView estará sempre centrado.

For Linear Layout

			
					<?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">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Hello World" />

</LinearLayout>

			
	

For Relative Layout

			
					<?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">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center" 
        android:text="Hello World" />

</RelativeLayout>

			
	

Você pode centralizar o texto em um TableRow em um TableLayout.

			
					<TableRow android:id="@+id/rowName"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:padding="5dip" >
    <TextView android:id="@+id/lblSomeLabel"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:gravity="center"
              android:layout_width="0dp"
              android:layout_weight="100"
              android:text="Your Text Here" />
</TableRow>