Skip to content Skip to sidebar Skip to footer

Font Size Of Text

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, val

Solution 1:

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

<?xml version="1.0" encoding="utf-8"?>
       <resources>
           <dimen name="textsize">14sp</dimen>

       </resources>

and paste it below code in values-w360dp-mdpi dimens.xml

<?xml version="1.0" encoding="utf-8"?>
       <resources>
           <dimen name="textsize">18sp</dimen>
       </resources>

then apply text size on your activity

android:textSize="@dimen/textsize"

Solution 2:

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.

enter image description here

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.


Solution 3:

Just create layout folders like layout, layout-small, layout-large, layout-xlarge then create values folders like values, values-ldpi, values-mdpi, values-hdpi, values-xhdpi. Then you can create values folder depending upon height or width and belongs to ldpi or mdpi i.e values-w360dp-mdpi or values-h600dp-mdpi. Then android automatically picks layout depending upon screen size and values on depending height or width.


Solution 4:

Try to add this in your AndroidManifest.xml

<supports-screens android:anyDensity="true"
                  android:largeScreens="true"
                  android:normalScreens="true"
                  android:resizeable="true"
                  android:smallScreens="true"/>

Solution 5:

Just instead yourvalues (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


Post a Comment for "Font Size Of Text"