18

xml レイアウトに 1 つの ImageView と 1 つの TextView があります。ImageView の右側に Web サービスで取得した以下のテキストを表示したいと思います。その1つの 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 は View をラップし 、ここではテキストビューを img ビューの周りにラップします

どうやら、解決策は説明されているように Spannable と ImageSpan を使用することです この回答Textview wrap around View

別の解決策は、webview を使用して html でレイアウトすることです。

于 2012-11-23T10:27:24.067 に答える