我的xml布局中有一个ImageView和一个TextView。我想在ImageView的右边显示我通过webservice获得的下面的文本。我能用那个TextView显示那个文本吗?
我试图在xml布局中给android:singleLine=设置“false”,但是没有用。
发布于 2012-11-23 18:27:51
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-23 18:27:24
这里已经讨论过了:Textview wrap around View和wrap text view around img view
显然,一种解决方案是使用Spannable和ImageSpan,如下所述的答案是Textview wrap around View
另一种解决方案是使用webview,并在html中进行布局。
https://stackoverflow.com/questions/13526949
复制相似问题