如何有一个圆形的TextView [英] How to have a circular TextView

查看:120
本文介绍了如何有一个圆形的TextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图让一个圆形的TextView 。其中,我想,以适应整个空间上面的圆形泡沫,如下面的图像了一圈。

I have been trying to make a circular TextView. Its a circle in which I want to accomodate whole space above a circular bubble as shown in image below.

请参见附加的图像。

在此图像中,我们有一个圆形的气泡在它的圆形文本。 我已经尝试设置椭圆形的.xml 的TextView 的背景,但仍然没有运气。

In this image, we have a circular bubble with circular text in it. I have already tried setting oval shape .xml as background of TextView but still no luck.

编辑:

由于文本长度的增加。它必须减少大小以适合在圈内。这是考虑最困难的部分。

As text length increase. It must reduces in size to fit inside the circle. This is the hardest part to think about.

推荐答案

您需要创建一个自定义视图,从的TextView 延伸可能,手动设置圈为背景图,并计算文本宽度/打破行根据文本的宽度。

You need to create a custom view, extending from TextView probably, setting the circle as background image, and calculate the text width / break the lines manually according to the width of the text.

要计算一个字符串的宽度,请参见如何计算字符串像素字体宽度?

To calculate the width of a string, see How to calculate string font width in pixels?

一些数学和计算是必修课来衡量每行的可用空间;但我认为这是唯一的办法,因为没有标准组件都来做到这一点。

Some math and calculations is required of course to measure the available space per line; but I think that's the only way, as there's no standard component out there to do it.

要放置文本到视图中,使用的drawText 的<一个href="http://developer.android.com/reference/android/graphics/Canvas.html#drawText%28java.lang.String,%20float,%20float,%20android.graphics.Paint%29"><$c$c>Canvas类。

To place the text onto the view, use drawText of the Canvas class.

这篇关于如何有一个圆形的TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆