Align the author’s text in the last line of the quote, if there is a place, otherwise put it on a new line

enter image description here

Above is an example of the output I want. Notice that “from John” is aligned to the right on the last line of the quote.

enter image description here

If there is not enough space, I would like the author to appear on a new line, but still right-aligned.

+4
source share
3 answers

in this case you should take two different TextViews and give the value of gravity = "right" for the second

0
source

replace your xml with this ...

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
 android:orientation="vertical"
 android:padding="5dip" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginBottom="3dip"
android:layout_marginTop="3dip"
android:background="#ffffff" >

<TextView
    android:id="@+id/name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:maxLines="5"
    android:padding="2dp"
    android:text="Loren ipsum Loren ipsum Loren ipsum Loren ipsum Loren ipsum Loren ipsum Loren ipsum Loren ipsum Loren ipsum Loren ipsum Loren ipsum"
    android:textColor="#454545"
    android:textSize="9sp" />
  </LinearLayout>

  <RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<TextView
    android:id="@+id/by"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
   android:layout_marginRight="15dp"
    android:text="by john"
    android:textColor="#454545"
    android:textSize="9sp" />


 </RelativeLayout>

  </LinearLayout>

enter image description here

0
source

: , .

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="horizontal"
android:padding="5dip" >

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    >

    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="2dp"
        android:text="Loren ipsum Loren ipsum Loren ipsum Loren ipsum Loren ipsum Loren  Loren n ipsum Loren ipsum Loren ipsum Loren  Loren ipsum"
        android:textColor="#454545"
        android:textSize="9sp" />

    <TextView
        android:id="@+id/by"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginRight="15dp"
        android:text="by john"
        android:textColor="#454545"
        android:layout_marginTop="14dp"
        android:textSize="9sp" />
</RelativeLayout>

0

Source: https://habr.com/ru/post/1537331/


All Articles