Quantcast
Channel: Android Step-by-Step
Viewing all articles
Browse latest Browse all 25

How to Center a TextView within a RelativeLayout

$
0
0
android:layout_centerInParent
This only works in Relativelayout View. It does not work in LinearLayout.
If true, centers this child horizontally and vertically within its parent.

1. In your main.xml file, add a RelativeLayout.

2. Add a TextView to the main.xml file.

3. Add the below line between the <TextView> tags. This will center the TextView horizontally and vertically within its parent.

android:layout_centerInParent="true"

4. Compile and run!

Next Recommended Article: android:gravity - Move Text inside a EditText (center, top, bottom, right, left, and more)

Resources:
http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html#attr_android:layout_centerInParent


Viewing all articles
Browse latest Browse all 25

Latest Images

Trending Articles



Latest Images