如何将文本分成两个TextView,就像它们是一个TextView一样?(涉及IT技术)

6
我有一个列表视图,每个项目都有两个图片,一个在右边,一个在左边。它们之间有一个文本视图,通过数据填充。如果文本很长,它可以继续向下,但是就像您在图像中看到的那样,有很多空白空间。我希望也能利用这个空间来显示文本。我在网上找了一些东西,比如http://code.google.com/p/android-flowtextview/downloads/detail?name=FlowTextDemo.zip&can=2&q=,但这没有用。我不想失去图像的控制,因为我需要它们的点击方法。最好的方法是什么?我想也许我可以在图像之间放置一个文本视图,并在另一个文本视图下方,当第一个被填充时继续在第二个文本视图中,但是我怎么知道第一个文本视图可以容纳多少个字母呢?enter image description here
1个回答

5
我不明白为什么你不能使用你提供的 FlowTextView 。它是从 RelativeLayout 继承而来,可以将文本流动地包围在任何子视图周围。这些子视图可以是图片,并按照您通常在 RelativeLayout 中的方法进行定位。他们的 onClick 方法应该也能正常工作。
<com.pagesuite.flowtext.FlowTextView
    android:id="@+id/tv"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/the_text >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:onClick="onTopLeftClick"
        android:src="@drawable/top_left_image" />
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:onClick="onTopRightClick"
        android:src="@drawable/top_right_image" />

</com.pagesuite.flowtext.FlowTextView>

你需要在代码中设置文本,否则就要扩展FlowTextView并定义自己的自定义属性以从xml中设置文本。


我的错。你是对的。我给图像添加了一个android:id,然后我使用了ImageView test= (ImageView) tv.findViewById(R.id.idimage); - Learning from masters
@Learningfrommasters - 很高兴它起作用了。顺便说一句,那个链接真是不错的发现。 - Ted Hopp

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接