[英]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. (例如,使用SpannableString )不幸的是,这真的不是一件容易的事。 The easiest solution would be to use a library called FlowTextView
( Click ). 最简单的解决方案是使用一个名为FlowTextView
的库( Click )。
A TextView that extends RelativeLayout. 扩展RelativeLayout的TextView。 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. 此小部件具有使用Html.fromHtml(“ <您的标记... />”)对HTML的基本支持,它将识别链接,粗体斜体等。
<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 您可以使用TextView的drawableRight
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.