Android下如何计算要显示的字符串所占的宽度和高度

来源:互联网 发布:剑网3萝莉捏脸数据 编辑:程序博客网 时间:2024/05/01 22:40

查询了google发现在android一下有几种方法可以做到,但是经过实际测试发现下面这种方法是最准确的


Rect bounds = new Rect();String text = "Hello World";TextPaint paint;paint = findViewById(R.id.hello_world).getPaint();paint.getTextBounds(text, 0, text.length(), bounds);int width = bounds.width();



原创粉丝点击