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

时间:2014-08-26 07:49:07

标签: android android-layout

image

我希望显示一个长文本,它将图像左侧的文本添加到图像的左侧,但是当它超出图像的高度时,它应该将其右侧与父图像对齐。

我尝试过类似的东西,但它不起作用:

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

感谢。

2 个答案:

答案 0 :(得分:0)

有多种方法可以实现这一目标。 (例如使用SpannableString)遗憾的是没有一个真的很容易。最简单的解决方案是使用名为FlowTextViewClick)的库。

  

扩展RelativeLayout的TextView。该文本将环绕布局中的任何子视图。

     

此小部件使用Html.fromHtml(&#34;&lt; your markup ... /&gt;&#34;)对HTML进行基本支持。它将识别链接,粗体斜体等。

答案 1 :(得分:0)

<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

相关问题