根据平板电脑动态文本尺寸变化 [英] Dynamic Text size change according to tablet

查看:167
本文介绍了根据平板电脑动态文本尺寸变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于所有的努力,我终于达到了android的我的第一个应用程序的结束。并感谢所有。但即将结束以后,我明白了一件事,我的应用程序的文字大小是常见于所有平板电脑的大小。因此,我将重新帧我的问题。

With all effort,I finally reached to the end of my first app in android. And thanks to all. But after coming to end, I realized one thing that my app text size is common in all tablet sizes. So I will re frame my question.

问题:我用我自己的自定义文本大小在整个应用程序。有些什么满意的7英寸平板电脑。但是,当我在寻找同样的事情8.9英寸,10.1英寸的平板电脑是其含有大量的空格和文本大小也比较小。那么,有没有一些方法,我可以根据我的平板电脑尺寸改变文字大小???它可能看起来新手的问题,但我挣扎,是因为相同的应用程序,它看起来棒极了7英寸,是失去它的本质在8.9和10.1英寸。或者还有别的东西,我可以做我的应用程序的相同。 可能的解决方案: - 作为我演讲的题目是指有一些方法来改变文字大小药片大小的变化。无论是动态或任何其他方式。

Problem: I used my own custom text size in entire app. and some what satisfied with 7 inch tablet. But when I am looking the same thing in 8.9 inches and 10.1 inch tablet its containing lots of white spaces and text size are also relatively small. So is there some way that I can change the text size according to my tablet size??? It may look novice question but I am struggling with this because the same app which look wonderful in 7 inches, is loosing its essence in 8.9 and 10.1 inches. Or there is something else which I could do with my app for the same. Probable Solution:- As my topic indicates is there some way to change the text size as tablet size changes. Either dynamically or any other way.

EDITED :: 作为每猎豹答案,做法是正确的,但我不能做到这一点对每个布局按钮和文本框等领域。有数百场像这样的单一的应用程序。我可以做一些一个地方,并调用它需要的属性。是自定义标签的做法,我期待for.Is有可能????

EDITED:: As per Cheeta answer, approach is correct but I can't do it for each layout buttons and textfields and other field. There are hundreds of field like this in single app. Can I do it in some one place and call it required attribute. Is custom tag is approach which I am looking for.Is it possible????

任何帮助将AP preciated。 先谢谢了。

Any help will be appreciated. Thanks in advance.

注意我还没有达到一个答案,但猎豹答案有些通往正确道路。我打他的回答是正确的,虽然也有对他的回答几个对齐问题。任何其他的答案永远是受欢迎的。 感谢

推荐答案

我有同样的问题,但我意识到 SP / DB 不是有效的处理这类的问题,我处理我的对齐方式和字体大小相关的东西programtically。

I was Having Same Problem but what i realized sp/db are not efficient for dealing with this kind of problem, I handled my alignment and font size related stuff programtically.

这里的步骤,我怎么处理这个问题。

here are the steps, how i handled this problem.

  • 在计算设备的屏幕宽度和高度
  • 使用集 TextView.setTextSize(单位,尺寸),所在单位参数 TypedValue.COMPLEX_UNIT_PX 和尺寸参数是屏幕的总宽度的百分比。通常情况下,对我来说,总宽度为字体的0.5%是合适的。你可以尝试其他的总宽度的百分比,如0.4%或0.3%的实验。
  • Calculate Screen Width and Height of Your device
  • Use Set TextView.setTextSize(unit, size), where the unit parameter is TypedValue.COMPLEX_UNIT_PX and the size parameter is percent of the total width of your screen. Normally, for me, .5% of total width for font is suitable. You can experiment by trying other total width percentages, such as 0.4% or 0.3%.

这样,你的字体尺寸将永远适合每个文本/屏幕尺寸。

This way your font size will be always suitable for each and every text/screen size.

这篇关于根据平板电脑动态文本尺寸变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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