Reputation: 17
I am new in android and working on an application. I have read a lot of articles, blogs about how to set Text Size
correctly in android, but unfortunately they didn't tell me something useful.
I use two different AVDs to test my application.
One of them is Nexus One 480 * 800 hdpi
and another one is Nexus 7 800*1280 tvdpi
.
I have created my UI in Nexus 7
. I have set TextSize
to 72 Sp & it shows very well! But when I changed the AVD it was not OK. The text was too big.
I thought if I use sp
unit to define textSize
, everything will go very well, but it didn't.
I have tried following things:
I used sp
unit but it didn't work .
I tried to find a relation between density and textSize
in one avd , and set that so that correct textSize
is shown in any in any AVD , but it didn't work too.
(During my experiments I found 213 density for Nexus 7. It was bigger than Nexus One.) I calculated density with this code:
int densityDpi = (int)(metrics.density*160);
I read an article about this problem & it explained, you should create more than one UI for an application. According to this method, UI always shows correctly, but it didn't explain clearly how to do this.
Upvotes: 0
Views: 162
Reputation: 978
Easy way is use res and override dimens.xml due to device used
Android gets the best resource base on the device used so you can use it do style layout, change language, theming and ofcourse, sizing.
android:textSize="@dimen/abc_text_size_body_1_material"
You need define abc_text_size_body_1_material in
res/values/dimens.xml
res/values-hdpi/dimens.xml
res/values-tvdpi/dimens.xml
More info http://developer.android.com/guide/practices/screens_support.html
Upvotes: 1