Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edit text view with image and text wrapped around image

I am building a rich text editor. I have implemented text formatting like bold italic etc and also paragraph formatting like blockQuote. Now I would like to add images in editor and text should wrap around it. I have implemented all these using SpannableString() and Spanned() and StyleSpan().

I can add image to a line using ImageSpan(), but that add it inline and its just there in place of a character , what I want is to insert it in paragraph and rest of text should wrap around it. I am able to add image at the beginning of text by following code.. but I cannot align it center and right.

 SpannableString string = new SpannableString("Text with icon and padding");
 string.setSpan(new IconMarginSpan(bitmap, 30), 0, string.length(),
 Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

How to do it ? any example? or what procedure to follow?

like image 555
Circle Avatar asked Mar 20 '18 16:03

Circle


People also ask

How do I wrap text around an image?

Wrap text around a picture or drawing objectSelect the picture or object. Select Format and then under Arrange, select Wrap Text.

How do I make text wrap around an image in HTML?

Use the markup code <BR CLEAR=”left” /> to flow text around images on opposite sides of your Web pages.

How do I make text wrap around an image in CSS?

Enter . left { float: left; padding: 0 20px 20px 0;} to the stylesheet to use the CSS "float" property. (Use right to align the image to the right.) If you view your page in a browser, you'll see the image is aligned to the left side of the page and the text wraps around it.

What is the text wrapping?

Text wrapping refers to how images are positioned in relation to text in a document, allowing you to control how pictures and charts are presented.


1 Answers

you can fulfill your requirement like below:

you can set your image in imageview and your text in Html.fromHtml("here put your text")

gradle file:

compile 'com.github.deano2390:FlowTextView:2.0.5' 

your XML layout:

<uk.co.deanwild.flowtextview.FlowTextView
    android:id="@+id/ftv"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

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

</uk.co.deanwild.flowtextview.FlowTextView>

your java file:

FlowTextView flowTextView = (FlowTextView) findViewById(R.id.ftv);
             Spanned html = Html.fromHtml("here put your text");
             flowTextView.setText(html);

you may get help by this link https://github.com/deano2390/FlowTextView also

I hope it help you..!

like image 161
Ketan Patel Avatar answered Sep 22 '22 19:09

Ketan Patel