如何用android中的Image下面的内容填充空白区域

时间:2012-11-23 10:14:54

标签: android android-layout xml-layout

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

enter image description here

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

2 个答案:

答案 0 :(得分:22)

https://github.com/deano2390/flowtextview

screenshot

使用示例:

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

您的代码:

for Text:

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

答案 1 :(得分:1)

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

显然,解决方案是使用Spannable和ImageSpan,如下所述Textview wrap around View

另一种解决方案是使用webview并以html格式进行布局。