Reputation: 1078
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) Would I programmatically change the text size in styles.xml during launch?
This option is convenient because I wouldn't have to make 150+ XML Layouts.
2) Would I create three separate XML Layout's for the three sizes?
I would have to copy+paste each Style (*.small, *.med, *.large)... this sound like it will take a lot of work.
Any comments?
Upvotes: 3
Views: 2791
Reputation: 16209
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.
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 value
s and layout
s 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).
Upvotes: 3
Reputation: 6322
Well I'm not quite sure I fully understand your question, but it seems like you're simply worrying about font size, which can be standardized by using "scaled pixels" (sp) when defining TextSize in your XML. You can programmatically change the text size as well (#1 you suggested) by grabbing a TextView by its Id and setting the text size via the setTextSize() method.
Let me know if this isn't the answer you were looking for.
Upvotes: 1