在本文中,我们将详细介绍Android并计算给定字体和字体大小的单行字符串的大小?的各个方面,并为您提供关于android获取字符串长度的相关解答,同时,我们也将为您带来关于Aframe字体的字体大小
在本文中,我们将详细介绍Android并计算给定字体和字体大小的单行字符串的大小?的各个方面,并为您提供关于android获取字符串长度的相关解答,同时,我们也将为您带来关于Aframe字体的字体大小和字体类型、android APP字体大小,不随系统的字体大小变化而变化的方法、android canvas drawText从宽度设置字体大小?、Android Studio怎么更改字体大小 Android Studio更改字体大小的方法的有用知识。
本文目录一览:- Android并计算给定字体和字体大小的单行字符串的大小?(android获取字符串长度)
- Aframe字体的字体大小和字体类型
- android APP字体大小,不随系统的字体大小变化而变化的方法
- android canvas drawText从宽度设置字体大小?
- Android Studio怎么更改字体大小 Android Studio更改字体大小的方法
Android并计算给定字体和字体大小的单行字符串的大小?(android获取字符串长度)
解决方法
Paint p = new Paint(); p.setTypeface(TypeFace obj); // if custom font use `TypeFace.createFromFile` p.setTextSize(float size); float textWidth = p.measureText("Your string"); // you get the width here and textsize is the height.
Aframe字体的字体大小和字体类型
我发现了如何更改任何看到此字体的人的字体大小:缩放有效。它的默认值为1 1 1,但是您显然可以更改它。
android APP字体大小,不随系统的字体大小变化而变化的方法
从android4.0起系统设置的”显示“提供设置字体大小的选项。这个设置直接会影响到所有sp为单位的字体适配,所以很多app在设置了系统字体后瞬间变得面目全非。
Resources res = super.getResources();
Configuration config=new Configuration();
config.setToDefaults();
res.updateConfiguration(config,res.getDisplayMetrics() );
虽然google推荐使用sp作为字体的单位,但实际的开发过程中通常是根据UIUE的设计稿来换算 sp(px换算sp)。而sp即使在同一种密度下其值也不尽相同。比如在240dpi的设备,如果是480x800分辨率这个值通常是1.5倍 (scaledDensity=1.5),如果是480xZ(z>800)那么这个值有可能大于1.5。这无疑给设备的适配带来更多的困难和陷阱。所以个人通常建议使用dpi来作为字体的单位
对于个别app不需要根据系统字体的大小来改变的,可以在activity基类(app中所有的activity都应该有继承于我们自己定义的一个BaseActivity类)中加上以下code:
@Override
public Resources getResources() {
Resources res = super.getResources();
Configuration config=new Configuration();
config.setToDefaults();
res.updateConfiguration(config,res.getDisplayMetrics() );
return res;
}
android canvas drawText从宽度设置字体大小?
我想canvas
使用指定宽度绘制文本.drawtext
例如,400px
无论输入文本是什么,文本的宽度都应始终为。
如果输入文本较长,则将减小字体大小;如果输入文本较短,则将相应地增大字体大小。
答案1
小编典典这是一种更有效的方法:
/** * Sets the text size for a Paint object so a given string of text will be a * given width. * * @param paint * the Paint to set the text size for * @param desiredWidth * the desired width * @param text * the text that should be that width */private static void setTextSizeForWidth(Paint paint, float desiredWidth, String text) { // Pick a reasonably large value for the test. Larger values produce // more accurate results, but may cause problems with hardware // acceleration. But there are workarounds for that, too; refer to // http://stackoverflow.com/questions/6253528/font-size-too-large-to-fit-in-cache final float testTextSize = 48f; // Get the bounds of the text, using our testTextSize. paint.setTextSize(testTextSize); Rect bounds = new Rect(); paint.getTextBounds(text, 0, text.length(), bounds); // Calculate the desired size as a proportion of our testTextSize. float desiredTextSize = testTextSize * desiredWidth / bounds.width(); // Set the paint for that size. paint.setTextSize(desiredTextSize);}
然后,您所要做的就是setTextSizeForWidth(paint, 400, str);
(400为问题中的示例宽度)。
为了获得更高的效率,您可以使它Rect
成为静态类成员,从而避免每次实例化它。但是,这可能会引入并发问题,并且可能会阻碍代码的清晰度。
Android Studio怎么更改字体大小 Android Studio更改字体大小的方法
android studio 如何调整字体大小?困扰于 android studio 字体过小或过大?php小编新一带来详细指南,一步步教你轻松调整字体大小,优化开发体验。快来了解如何自定义 ide 的字体设置,提升你的编程效率,优化你的开发流程。
第一步:打开Android Studio,进入主界面。
第二步:进入软件后,点击菜单栏的File。
第三步:在File选项中选择Settings。
第四步:进入Settings选择Editor Font。
第五步:找到size,并更改。
第六步:最后点击OK即可。
以上就是Android Studio怎么更改字体大小 Android Studio更改字体大小的方法的详细内容,更多请关注php中文网其它相关文章!
关于Android并计算给定字体和字体大小的单行字符串的大小?和android获取字符串长度的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于Aframe字体的字体大小和字体类型、android APP字体大小,不随系统的字体大小变化而变化的方法、android canvas drawText从宽度设置字体大小?、Android Studio怎么更改字体大小 Android Studio更改字体大小的方法等相关内容,可以在本站寻找。
本文标签: