Android relative layout, right align a textview below another textview

Drunken Daddy

I've been struggling with this problem in layout for sometime now. To make things simpler, I've a screenshot.

enter image description here

I want to right align that textview which has content "3 hours ago" to the right. For this TextView I've layout_below property set to the Linearlayout above(contains two textviews which has contents 36.90 & deg celius as in the picture).

I tried android:layout_alignRight="@+id/rl1", It aligns the textview to the right. But when the content of hours ago TextView is bigger than that above, It get clipped off().

Someone, Please help me.

Here's code( not the whole code). just the part on the right side

<RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            >
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:id="@+id/rl1">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/subVitalValueTextView"
                    android:gravity="center_vertical"
                    android:text="5.05"
                    android:textSize="22dp"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/subVitalUnitTextView"
                    android:text="feet"
                    android:paddingLeft="5dp"/>
            </LinearLayout>
            <TextView
                android:layout_marginTop="-6dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/subVitalTimeAgoTextView"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="5 hours ago"
                android:fontFamily="sans-serif-thin"
                android:layout_below="@+id/rl1"/>
</RelativeLayout>
Murtaza Khursheed Hussain

Try the following

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

    <ImageView
        android:id="@+id/subVitalImageView"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="14dp"
        android:layout_marginTop="8dp"
        android:layout_toRightOf="@+id/subVitalImageView"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/textView1"
        android:layout_marginLeft="42dp"
        android:layout_toRightOf="@+id/textView1" >

        <TextView
            android:id="@+id/subVitalValueTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:text="5.05"
            android:textSize="22dp" />

        <TextView
            android:id="@+id/subVitalUnitTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@+id/subVitalValueTextView"
            android:paddingLeft="5dp"
            android:text="feet" />

    </RelativeLayout>

    <TextView
        android:id="@+id/subVitalTimeAgoTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/relativeLayout1"
        android:layout_below="@+id/relativeLayout1"
        android:fontFamily="sans-serif-thin"
        android:text="5 hours ago"
        android:textAppearance="?android:attr/textAppearanceSmall" />

</RelativeLayout>

Option 2

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

    <ImageView
        android:id="@+id/subVitalImageView"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="14dp"
        android:layout_marginTop="8dp"
        android:layout_toRightOf="@+id/subVitalImageView"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/subVitalImageView"
        android:layout_alignParentRight="true"
        android:layout_marginLeft="42dp"
        android:layout_toRightOf="@+id/textView1" >

        <TextView
            android:id="@+id/subVitalValueTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:text="5.05"
            android:textSize="22dp" />

        <TextView
            android:id="@+id/subVitalUnitTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@+id/subVitalValueTextView"
            android:paddingLeft="5dp"
            android:text="feet" />

        <TextView
            android:id="@+id/subVitalTimeAgoTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/subVitalValueTextView"
            android:fontFamily="sans-serif-thin"
            android:text="5 hours ago"
            android:textAppearance="?android:attr/textAppearanceSmall" />
    </RelativeLayout>

</RelativeLayout>

Result

enter image description here

Option 3

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

    <ImageView
        android:id="@+id/subVitalImageView"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="14dp"
        android:layout_marginTop="8dp"
        android:layout_toRightOf="@+id/subVitalImageView"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true" >

        <TextView
            android:id="@+id/subVitalValueTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:text="5.05"
            android:textSize="22dp" />

        <TextView
            android:id="@+id/subVitalUnitTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@+id/subVitalValueTextView"
            android:paddingLeft="5dp"
            android:text="feet" />

        <TextView
            android:id="@+id/subVitalTimeAgoTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/subVitalValueTextView"
            android:fontFamily="sans-serif-thin"
            android:text="5 hours ago"
            android:textAppearance="?android:attr/textAppearanceSmall" />
    </RelativeLayout>

</RelativeLayout>

Result

enter image description here

Option 4

  <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/subVitalImageView"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true" >

        <TextView
            android:id="@+id/subVitalUnitTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/subVitalTimeAgoTextView"
            android:layout_alignParentRight="true"
            android:paddingLeft="5dp"
            android:text="feet" />

        <TextView
            android:id="@+id/subVitalValueTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_toLeftOf="@+id/subVitalUnitTextView"
            android:gravity="center_vertical"
            android:text="5"
            android:textSize="22dp" />

        <TextView
            android:id="@+id/subVitalTimeAgoTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:fontFamily="sans-serif-thin"
            android:text="5 hours ago"
            android:textAppearance="?android:attr/textAppearanceSmall" />

    </RelativeLayout>

Result

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

In a relative layout, how to display the run time textview below another textview?

From Dev

Android align textview to right

From Dev

Android TextView align right

From Dev

Android align textview to right

From Dev

How to align buttons below textview in linear layout

From Dev

Align shape to center of textview on Relative layout

From Dev

Center align TextView in android layout

From Dev

Android - How to align an image center relative to the textview

From Dev

Android XML ImageView below TextView but needs to align bottom with textView

From Dev

How to align ImageView & TextView align right in a Linear Layout

From Dev

Android textview is not showing up in relative layout.

From Dev

Android TextView Right Align in LinearLayout Programmatically

From Dev

Android relative layout - align images to the right

From Dev

textview not align center below of imageview

From Dev

Android relative layout - align a widget parent right based on another widget's visibliity

From Dev

why cannot i see a textView above another view in relative layout?

From Dev

Android textfield and textview from a layout to another

From Dev

How to wrap textview to relative layout

From Dev

How to align a TextView to the right with LinearLayout

From Dev

Android How to change layout_below to TextView programmatically

From Dev

Align text to the right and center vertically, xamarin android textview

From Dev

Align TextView baseline and another TextView bottom

From Dev

set textview below textview in android programmatically

From Dev

Android Layout TextView

From Dev

Android Textview Layout issue

From Dev

Cant align an image center relative to the textview

From Dev

Android TextView below EditText disappear

From Dev

Android: TextView not appearing below ListView

From Dev

Textview in center below of imageview Android

Related Related

  1. 1

    In a relative layout, how to display the run time textview below another textview?

  2. 2

    Android align textview to right

  3. 3

    Android TextView align right

  4. 4

    Android align textview to right

  5. 5

    How to align buttons below textview in linear layout

  6. 6

    Align shape to center of textview on Relative layout

  7. 7

    Center align TextView in android layout

  8. 8

    Android - How to align an image center relative to the textview

  9. 9

    Android XML ImageView below TextView but needs to align bottom with textView

  10. 10

    How to align ImageView & TextView align right in a Linear Layout

  11. 11

    Android textview is not showing up in relative layout.

  12. 12

    Android TextView Right Align in LinearLayout Programmatically

  13. 13

    Android relative layout - align images to the right

  14. 14

    textview not align center below of imageview

  15. 15

    Android relative layout - align a widget parent right based on another widget's visibliity

  16. 16

    why cannot i see a textView above another view in relative layout?

  17. 17

    Android textfield and textview from a layout to another

  18. 18

    How to wrap textview to relative layout

  19. 19

    How to align a TextView to the right with LinearLayout

  20. 20

    Android How to change layout_below to TextView programmatically

  21. 21

    Align text to the right and center vertically, xamarin android textview

  22. 22

    Align TextView baseline and another TextView bottom

  23. 23

    set textview below textview in android programmatically

  24. 24

    Android Layout TextView

  25. 25

    Android Textview Layout issue

  26. 26

    Cant align an image center relative to the textview

  27. 27

    Android TextView below EditText disappear

  28. 28

    Android: TextView not appearing below ListView

  29. 29

    Textview in center below of imageview Android

HotTag

Archive