简体   繁体   中英

How to align image to top right corner of textView?

图片

I want to display a long text, which alings its right to the left of image, but when it goes beyond the height of image, it should align its right to parent.

I tried something like this, but its not working:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

   <ImageView
    android:id="@+id/image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:src="@drawable/next" />

   <TextView
    android:id="@+id/textView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@+id/image"
    android:text="Text...." />

</RelativeLayout>

Thanks.

There are multiple ways how you could achieve this. (eg using a SpannableString ) Unfortunately none is really easy. The easiest solution would be to use a library called FlowTextView ( Click ).

A TextView that extends RelativeLayout. The text will wrap around any child views inside the layout.

This widget has basic support for HTML using Html.fromHtml("< your markup ... />") It will recognise links, bold italic etc.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:drawableRight="@drawable/next"
        android:text="Text...." />
</RelativeLayout>

You can use TextView's drawableRight

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