Skip to content Skip to sidebar Skip to footer

Vertically Centering Two Textviews In A Relativelayout

What's Happening I am writing a PopupWindow containing two TextViews, where the second TextView should be centered vertically in the popup, and the first TextView should be directl

Solution 1:

As Sushil said, you can probably remove your LinearLayout completely. The following fix should work; if it does, try removing the linear layout as well.

The issue here is the android:gravity="center" on the RelativeLayout. If you remove that, you can get the placement you desire:

<RelativeLayoutandroid:layout_width="match_parent"android:layout_height="match_parent" >

Solution 2:

You can remove your Linearlayout simply. Right now your textview are child views of Relativelayout which is a child view to LinearLayout.

<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent" >

        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center" >

        <TextViewandroid:id="@+id/first_name"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_centerInParent="true"android:gravity="center"android:singleLine="true"android:text="Christopher" /><TextViewandroid:id="@+id/lbl_hello"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_above="@id/first_name"android:gravity="center"android:singleLine="true"android:text="@string/hello" /></RelativeLayout>

Solution 3:

Use this xml:

<RelativeLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_centerHorizontal="true"android:layout_centerVertical="true"android:layout_marginLeft="40dp"android:layout_marginRight="40dp"android:layout_marginTop="90dp"><TextViewandroid:id="@+id/inv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:text="@string/invfam"android:textColor="#f5f5f5"android:textSize="20dp" /><TextViewandroid:id="@+id/promo"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@+id/inv"android:gravity="center"android:layout_marginTop="10dp"android:text="Enjoy an additional 15 AED off your first video consultation. Sign up for a Health at Hand account and you will be credited 30 AED as a new user plus an extra 15 AED! #feel better today"android:textColor="#f5f5f5"android:textSize="14dp" /></RelativeLayout>

Post a Comment for "Vertically Centering Two Textviews In A Relativelayout"