Android - 用于文本的UI包装图像

tee*_*ink 8 android

无论如何要在图像周围包装TextView吗?这是人们在CSS中做的典型事情,如http://www.echoecho.com/htmlimages08.htm

谢谢,
Tee

Dea*_*ild 15

我为此编写了一个小部件:http: //code.google.com/p/android-flowtextview/

在此输入图像描述

此小部件扩展(因此表现得像)RelativeLayout,因此您可以添加子视图.该类公开了一个setText()方法,该方法允许您设置视图的文本(plain或spannable),然后调用invalidate()来呈现文本.该文本将填写子视图留下的任何空间.

用法示例:

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

然后在你的代码中:

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

如果您在使用此功能时遇到任何问题,请随时为您提供帮助,请在我的个人资料中查找


Rom*_*rik 4

为什么不直接使用 aWebView呢?将来您将有更多的自由来自定义布局。

如果 aWebView对于您的用例来说太重量级,您可能需要手动渲染文本和图像。您可能会在此 android-developers thread中找到一些相关信息。