In my case I have two text views, I want them to be centered in my activity.
The problem is when I use:
android:gravity="center_vertical|center_horizontal"
android:layout_centerInParent="true"
The two text views are above each other and I’m using LinearLayout as a parent.
You should remove the vertical and parent-based parts, and leave just the
for both of the
TextViews.If it’s enough, that the first TextView is centered vertically, then you can set it to
|center_vertical, and bind the second to this one withandroid:layout_below.If you need these text views to be exactly in the vertical center of the activity, then you should encapsulate them into an other (e.g. Linear)Layout with
android:height="wrap_content"andandroid:layout_centerInParent="true"(inRelativeLayout) orandroid:gravity="center_vertical|center_horizontal".