在Android中的TextView中管理大字体 [英] Manage large font size in TextView in Android

查看:62
本文介绍了在Android中的TextView中管理大字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在正常字体大小下,布局没有任何问题.但是,当用户从设置中更改字体大小并使其变大时,整个应用程序屏幕布局字体会变得非常大,从而使用户无法阅读它.

In normal font size layout is showing without any issues. But when user change font size from setting and make it big, whole app screen layout font become very huge so that user unable to read it.

在正常情况下

更改字体大小时

所以这里的问题是我不能保持固定的字体大小,我必须显示用户选择的字体大小.问题是字体越来越大,整个布局会垂直延伸.

So here issue is I cant keep fixed font size, I have to show user selected font size. Issue is as font become bigger and bigger whole layout will stretch vertically.

我希望下面有类似的东西.

I am expecting to have something like below.

因此,在字体放大时,我们可以有足够的空间来显示数据.

So when on font enlarge we can enough space to show data.

请帮助我.我是否可以使用响应式布局,以便根据可用的空间组件相应地显示.

Please help me. Can I have responsive layout so based on available space component get display accordingly.

推荐答案

像这样简单的事情呢?

public static final float getMeasureTextSize(float viewWidth, float viewHeight, final float scale /* 0.0F - 1.0F */, final String text)
{
    final Rect bounds = new Rect();
    final Paint paint = new Paint();
    paint.setTextSize((Math.min(viewWidth, viewHeight) / 250F) * 150F);
    paint.getTextBounds(text, 0, text.length(), bounds);
    if(bounds.width() > (viewWidth * scale) || bounds.height() > (viewHeight * scale)) {
        paint.setTextSize(viewWidth);
        paint.getTextBounds(text, 0, text.length(), bounds);
        viewWidth = viewWidth * ((viewWidth * scale) / bounds.width());
        viewHeight = viewHeight * ((viewHeight * scale) / bounds.height());
    }
    return Math.min(viewWidth, viewHeight);
}

然后以 0.7F 的比例尝试.

这篇关于在Android中的TextView中管理大字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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