繁体   English   中英

如何将图像对齐到textView的右上角?

[英]How to align image to top right corner of textView?

图片

我想显示一个长文本,该文本在图像的左侧紧紧保留,但是当它超出图像的高度时,则应将其右侧对齐父级。

我尝试了类似的方法,但是没有用:

<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>

谢谢。

有多种方法可以实现这一目标。 (例如,使用SpannableString )不幸的是,这真的不是一件容易的事。 最简单的解决方案是使用一个名为FlowTextView的库( Click )。

扩展RelativeLayout的TextView。 文本将环绕布局内的所有子视图。

此小部件具有使用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>

您可以使用TextView的drawableRight

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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