18

我的 xml 布局中有一个 ImageView 和一个 TextView。我想在ImageView右侧显示我通过webservice获得的文本。我可以使用那个 TextView 显示该文本吗?

在此处输入图像描述

我试图在 xml 布局中给出 android:singleLine="false" 但没有用。

4

2 回答 2

23

https://github.com/deano2390/flowtextview

截屏

示例用法:

 <com.pagesuite.flowtext.FlowTextView
     android:id="@+id/tv"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content" >

     <ImageView
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignParentLeft="true"
         android:layout_alignParentTop="true"
         android:padding="10dip"
         android:src="@drawable/android" />

     <ImageView
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignParentRight="true"
         android:layout_marginTop="400dip"
         android:padding="10dip"
         android:src="@drawable/android2" />

</com.pagesuite.flowtext.FlowTextView>

你的代码:

对于文本:

tv = (FlowTextView) findViewById(R.id.tv);                  
tv.setText("my string"); // using plain text    
tv.invalidate(); // call this to render the text

对于 HTML:

tv = (FlowTextView) findViewById(R.id.tv);              
Spanned spannable = Html.fromHtml("<html ... </html>");
tv.setText(spannable);  // using html
tv.invalidate(); // call this to render the text
于 2012-11-23T10:27:50.743 回答
1

这已经在这里讨论过: Textview wrap around View 和 here wrap text view around img view

显然,一个解决方案是使用 Spannable 和 ImageSpan 描述是这个答案Textview wrap around View

另一种解决方案是使用 webview 并让您在 html 中进行布局。

于 2012-11-23T10:27:24.067 回答