Search code examples
javaandroid-studiotextview

How to place a textView inside a textView in Android Studio?


So, I have a text view(A message), inside which I want to display the time, in the bottom right corner, while ensuring that the text content in the message does not overlay on it and wraps around. Now, I can manage the program part of how to get the time and set text and all, but what I am not able to do is to place the date inside the text view, something like this:

Here is what I have managed to do:

enter image description here

And here is what I want:

enter image description here

Could anyone please tell how can I place a text view like this inside another text View.

Thank You!


Solution

  • Here is an example to archive this.

    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        app:cardCornerRadius="8dp">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:background="@color/green_2">
    
            <TextView
                android:id="@+id/text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/text"
                android:layout_margin="8dp"/>
    
            <TextView
                android:id="@+id/time"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/time"
                android:layout_margin="8dp"
                android:drawablePadding="8dp"
                android:layout_gravity="end"
                app:drawableEndCompat="@drawable/ic_baseline_done_all_24" />
        </LinearLayout>
    </androidx.cardview.widget.CardView>
    

    And output be like this:-

    enter image description here

    Hope you helpful!