简体   繁体   中英

How to align the text on the right side of a picture?

I have an ImageView aligned to the parent right in a relativeLayout.

Here is my layout:

<RelativeLayout android:id="@+id/row" android:background="@null" style="@style/ListRow"
  xmlns:android="http://schemas.android.com/apk/res/android">

    <TextView android:textStyle="bold" android:textColor="@color/primary_text" android:text="Username" android:gravity="center_vertical" android:id="@+id/username" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:layout_toLeftOf="@id/avatar" />

    <LinearLayout android:gravity="center_vertical" android:id="@+id/time_item" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@id/username" android:layout_alignBottom="@id/username" android:layout_alignParentLeft="true">
        <TextView android:textSize="@dimen/font_size_small" android:text="12:00AM" android:textColor="@color/secondary_text" android:gravity="center_vertical" android:id="@+id/date" android:layout_width="wrap_content" android:layout_height="wrap_content" />
    </LinearLayout>

    <RelativeLayout android:id="@+id/avatar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5.0dip" android:layout_alignParentRight="true">
        <ImageView android:id="@+id/picture" android:src="@drawable/ic_launcher" android:layout_width="48.0dip" android:layout_height="48.0dip" android:scaleType="center" android:adjustViewBounds="true" />
        <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" />
    </RelativeLayout>

    <TextView android:textSize="@dimen/font_size_small" android:text="aslkndalskndlaksndlaskndlaksnlansldnaslkndalsdnaslkdnls" android:textColor="@color/primary_text" android:id="@+id/body" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_toLeftOf="@id/avatar" android:layout_below="@id/username" android:lineSpacingMultiplier="1.2" />

</RelativeLayout>

Here is what it looks like:

越来越

When starting a new line of text I want the text to align on to the right instead of the left. I have photoshopped what I want. Here is what I want:

想

Anyone know how I should modify my layout to where it does this? Thanks!

只需在TextView body添加一个属性即可。

android:gravity="right"

You are missing the android:gravity="right" element from your TextView Body. It should go like

<TextView android:gravity="right"... That simply makes the text originate on the right side of the TextView

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM