Android的编程方式更改样式 [英] Android Programmatically Change Style

查看:87
本文介绍了Android的编程方式更改样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有超过50 XML布局/页,需要一种方法来确定每个屏幕类型(小/中/大)基地字号。其实,我需要指定其他的东西,比如大小线性布局。

I have over 50 XML Layouts/pages and need a way to determine a "base" font size for each screen type (small/medium/large). Actually, I need to specify other things, such as sizes for linear layouts.

总之,我想区分小型/中型/大型设备之间的大小。

In short, I want to differentiate sizes between small/medium/large devices.

1)我会编程发射期间改变styles.xml文字大小?

这个选项很方便,因为我不会做150 + XML布局。

This option is convenient because I wouldn't have to make 150+ XML Layouts.

2)我将创建三个独立的XML布局的三个尺寸?

我将不得不复制粘贴+每个样式(*。小,* .med,*。大)...这听起来像这将需要大量的工作。

I would have to copy+paste each Style (*.small, *.med, *.large)... this sound like it will take a lot of work.

任何意见?

推荐答案

我假设你知道你应该使用可伸缩的单位在维奈的回答说:

I'm assuming that you know that you should use scalable units as stated in Vinay's answer:

http://developer.android.com/guide/practices/screens_support.html

我强烈建议不要从最佳做法偏离除非你真的知道自己在做什么。它只能带给你的道路问题。我不是一个职业球员,这就是为什么我尽量遵循的标准。好了,现在让我们来回答:

I strongly recommend not to deviate from the "best practices" unless you really know what you're doing. It can only bring you problems down the road. I'm not a pro, that's why I try to follow the standards. OK, now let's answer:

当您要使用不同尺寸,可伸缩的单位是不够的,必须声明它们的地方的。所以,你要不管是什么......这是不可避免的声明不同的文件。但话又说回来,只有当你的可扩展性的单位是不够的,在不同的屏幕提供了所需的视觉效果。

When you want to use different sizes, and scalable units are not enough, you must declare them somewhere. So you are going to declare different files no matter what... it's inevitable. But then again, only when your scalable units are not enough to provide the desired visual effect across different screens.

要做到这一点,你在文件夹申报。你看到的谷歌I / O的应用程序源在谷歌code?这是谷歌,而他们这样做非常好。如果你想通过例子来学习,这可能是最完整的资源,我能想到的。但它是一个有点可怕在第一。

To do that, you declare in value folders. Did you see the Google I/O app source on Google Code? It's "Google", and they do it very well. If you want to learn by example, that's probably the most complete resource I can think of. But it's a bit frightful at first.

这是这么多,这里讲(很多简单的问题......看来你真的不知道你的方式,对不起,如果不是这样),你最好还是不要下载一个源代码树。

It's so much to tell here (many simple questions... looks like you really don't know your way, sorry if it's not the case) that you are probably better off downloading that source tree.

当然,无论是布局取值文件夹以透明的方式工作(这是整点使用标准的),所以你不必担心在你的屏幕上的布局变化(处理键值样式时)和/或在运行时(同时解决样式和布局时)。

Of course, both the values and layouts folders work in a transparent fashion (that's the whole point of using the standards), so you don't need to worry about screen variations across your layouts (when addressing key-values styles) and/or at runtime (when addressing both style and layout).

这篇关于Android的编程方式更改样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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