I have created different layouts (layout, layout-small, layout-normal, layout-large, layout-xlarge)
and for values (values, values-ldpi, values-mdpi, values-nodpi, values-hdpi, values-xhdpi)
. I have one activity in my app to show text. I have scroll on text. And I set the values of text size in values-mdpi
. But when I run my app on emulator 3.2"QVGA(ADP2)(320 x 480:mdpi)
scroll on text work. But when I run my app on emulator 5.1"WVGA(480 x 800:mdpi)
all text on half screen and the size of text is small. I think android picking layout depending upon size and text size depending upon values-mdpi
. I want size of text big on large screen although they belong mdpi
.
My whole app is in portrait mode. And also same case with ldpi and hdpi. Please provide general solution.
Try like this
STEP : 1 first in
res
folder => values => dimensions.xml=> createdimensions.xml
file tovalues folder
in that create like below code depending on textsizeSTEP : 2 in java file write this line
Actually you don't need to create all these layout directories to handle text size. Just stick with the normal one (layout) and create different values directories with different text size for each resolution you want to support. so you have to add text size in other values directories.
At run-time Android will pick the correct text size.
you are using only portrait version, if you are using same structure of design for all devices you don't need to add four different layout for each pixel density.
create android values folders that supports different screen sizes.
Here first folder for 7inch android devices that have ANDROID version 3.1 or less. second one is for 7inch devices that have android version greater than 3.1. naming convention sw600 means smallest width of 600. so this folder works for width size 600 to 720. So create values-sw480dp and values-sw320 add values to dimens.xml file.
Android runtime automatically picks values from appropriate folder.
Just instead your
values (values, values-ldpi, values-mdpi, values-nodpi, values-hdpi, values-xhdpi)
, which are specifying the text font sizes for each density.Use text size specification based on screen size, like this:
values (values, values-small, values-normal, values-large, values-xlarge)
Alternatively to obtain better results for various devices you can combine density with screen size, like this:
values-normal-mdpi
That's all
Use this code, it works based on screen size:
Create folder like
values-mdpi
,values-w360dp-mdpi
in res folder.create dimens.xml on both folder.
and paste it below code in values-mdpi dimens.xml
and paste it below code in values-w360dp-mdpi dimens.xml
then apply text size on your activity