2012-11-23 30 views
16

Tôi có một ImageView và TextView trong bố cục xml của mình. Tôi muốn hiển thị văn bản bên dưới mà tôi nhận được bởi webservice ở phía bên phải của ImageView. Tôi có thể hiển thị văn bản đó bằng cách sử dụng một TextView đó không?Cách điền vào các khoảng trống có nội dung bên dưới Hình ảnh trong android

enter image description here

tôi đã cố gắng để cung cấp cho android: singleLine = "false" trong cách bố trí xml nhưng không sử dụng.

Trả lời

21

http://code.google.com/p/android-flowtextview/

enter image description here

Ví dụ sử dụng:

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

mã của bạn:

cho Text:

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

cho 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 
+0

tôi nhận văn bản từ webservice làm cách nào tôi có thể đặt văn bản đó thành html – Victor

+0

Bạn không phải chuyển văn bản thành html. không sử dụng spanable chỉ tv.setText (yourtextfromwebservice); – Talha

+0

làm cách nào tôi có thể chuyển đổi văn bản webservice đó thành html @talhakosen – Victor

Các vấn đề liên quan