编辑文本视图,图像和文本环绕图像

Cir*_*cle 14 java android android-edittext spannablestring spannable

我正在构建一个富文本编辑器.我已经实现了像粗体斜体等文本格式以及像blockQuote这样的段落格式.现在我想在编辑器中添加图像,文本应该环绕它.我用SpannableString()and Spanned()和实现了所有这些StyleSpan().

我可以使用添加图像到一行ImageSpan(),但是将其添加到内联中并将其添加到一个字符的位置,我想要的是将其插入段落中,其余的文本应该环绕它.我可以通过以下代码在文本的开头添加图像..但我无法将其对齐中心和右边.

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

怎么做 ?举个例子?或者要遵循什么程序?

Ket*_*tel 2

您可以满足您的要求,如下所示:

您可以在 imageview 中设置图像,在Html.fromHtml("here put your text")中设置文本

梯度文件:

compile 'com.github.deano2390:FlowTextView:2.0.5' 
Run Code Online (Sandbox Code Playgroud)

你的XML布局:

<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>
Run Code Online (Sandbox Code Playgroud)

你的java文件:

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

您也可以通过此链接https://github.com/deano2390/FlowTextView获得帮助

我希望它能帮助你..!