Android - UI for text wrap an image

后端 未结 3 2005
旧巷少年郎
旧巷少年郎 2020-12-09 06:10

Is there anyway to wrap a TextView around an image? It\'s the typical thing that people do in CSS like this http://www.echoecho.com/htmlimages08.htm

Thanks,
Tee<

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-09 07:02

    I've written a widget for this: http://code.google.com/p/android-flowtextview/

    enter image description here

    This widget extends (and therefore behaves like) a RelativeLayout so you can add child views. The class exposes a setText() method which allows you to set the view's text (plain or spannable) and then you call invalidate() to render the text. The text will fill in any space left by the child views.

    Example usage:

     
    
                
    
                
            
    

    Then in your code:

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

    Always happy to assist if you have any problems using this, find my email on my profile

提交回复
热议问题