I have the following layout i\'d like to make the textview appear in the center and middle of the view. How can i acheive this?
I\'ve tried adjusting the various gra
<TextView
...
android:layout_gravity="center"
....
/>
Use Relative Layout, it always gives more accurate and flexible layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
Set width of your textview to wrap_content, and set your LinearLayout to
android:gravity="center_horizontal"
None of the other answers worked for me. I had to use android:textAlignment="center"
My layouts were as follows
<LinearLayout...
<RelativeLayout...
<RelativeLayout....
<TextView
android:layout_centerInParent="true"
android:textAlignment="center"
simple i have tried to many answer but all answers are not working ......finally this methods works for me
<LinearLayout
android:layout_below="@+id/iv_divider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="@dimen/_10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/mycredits"
android:textColor="@color/colorGray"
android:gravity="center"
android:textSize="@dimen/_25dp" />
</LinearLayout>