开发者

Android HTML like Textwrapping in TextView

开发者 https://www.devze.com 2023-04-05 01:52 出处:网络
Is it possible to wrap text in android as we do in HTML? For example, in HTML when have have an image and some text on its left or right side. When the text inc开发者_开发知识库reases to the size of i

Is it possible to wrap text in android as we do in HTML? For example, in HTML when have have an image and some text on its left or right side. When the text inc开发者_开发知识库reases to the size of image, it starts from the beginning of the next line. like

Android HTML like Textwrapping in TextView

There is a single textview and an ImageView on its left.


I understand what you mean, then I suggest you write your own view, encapsulates it into a component, so should be able to meet your needs.


You can say that the content inside is set to String, the layout of the file it textview We know that to make parsing and display TextView Html code. You can use the

Spanned text = Html.fromHtml (source); tv.setText (text);

To achieve this with a simple and convenient. However, also shows how to make TextView Html in node images? We can see fromHtml another reconstruction:

`fromHtml (String source, Html.ImageGetter imageGetter, Html.TagHandler tagHandler)`

Can make to achieve what ImageGetter picture shows:

ImageGetter imgGetter = new Html.ImageGetter () {
              @ Override
              public Drawable getDrawable (String source) {
                    Drawable drawable = null;
                    drawable = Drawable.createFromPath (source); 
                    // Or fetch it from the URL
                    // Important
                    drawable.setBounds (0, 0,drawable.getIntrinsicWidth (), drawable
                                  . getIntrinsicHeight ());
                    return drawable;
              } };

As TagHandler, we need to use here, can pass null. I think he has to help you。 my wibsite is

  • http://onmyfree.sinaapp.com.

  • I foud a new way to slove it,it's use ImageSpan of TextView ,like this

    TextView tv = new TextView(this);
    
    SpannableString spanStr = new SpannableString("掌声那历史的房间里是副经理撒旦法阿斯顿及福利费是到发顺丰");
    ImageSpan imageSpan = new ImageSpan(this, R.drawable.a);
    spanStr.setSpan(imageSpan, 3, 5, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    tv.setText(spanStr);
    
    setContentView(tv);
    
    enter code here
    

    this website will help u ,linkToWebsite

    0

    精彩评论

    暂无评论...
    验证码 换一张
    取 消

    关注公众号