gpt4 book ai didi

Android - 用于文本换行图像的 UI

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:54:04 29 4
gpt4 key购买 nike

有没有办法将 TextView 包裹在图像周围?这是人们在 CSS 中做的典型事情 http://www.echoecho.com/htmlimages08.htm

谢谢,
三通

最佳答案

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

enter image description here

此小部件扩展(因此表现得像)一个 RelativeLayout,因此您可以添加 subview 。该类公开了一个 setText() 方法,该方法允许您设置 View 的文本(纯文本或可跨越文本),然后调用 invalidate() 来呈现文本。文本将填充 subview 留下的任何空间。

示例用法:

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

然后在你的代码中:

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

如果您在使用时遇到任何问题,我们很乐意为您提供帮助,请在我的个人资料中找到我的电子邮件

关于Android - 用于文本换行图像的 UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2474012/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com