【发布时间】:2012-11-23 10:14:54
【问题描述】:
我的 xml 布局中有一个 ImageView 和一个 TextView。我想在ImageView右侧显示我通过webservice获得的文本。我可以使用那个 TextView 来显示该文本吗?
我试图在 xml 布局中给 android:singleLine="false" 但没有用。
【问题讨论】:
标签: android android-layout xml-layout
我的 xml 布局中有一个 ImageView 和一个 TextView。我想在ImageView右侧显示我通过webservice获得的文本。我可以使用那个 TextView 来显示该文本吗?
我试图在 xml 布局中给 android:singleLine="false" 但没有用。
【问题讨论】:
标签: android android-layout xml-layout
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
【讨论】:
这里已经讨论过了: Textview wrap around View 在这里wrap text view around img view
显然,一个解决方案是使用 Spannable 和 ImageSpan 描述是这个答案Textview wrap around View
另一种解决方案是使用 webview 并让您在 html 中进行布局。
【讨论】: