Android font size in pt - android

I'm working on a Android project where I need to build my layouts based on a JSON layout file. This same file is also being used on an iOS app. So there is 1 file which will render the same layout on the Android as well as on the iOS.
The JSON layout file defines its font sizes based on the default iOS font unit.
From the Android docs:
Points - 1/72 of an inch based on the physical size of the screen.
And as far as I can find, iOS font sizes are also defined as 1/72 of an inch.
So based on this info, I'd say the following should be enough:
view.setTextSize(TypedValue.COMPLEX_UNIT_PT, fontSizeInIosUnit)
This however results in the text being too large. And it also seems to differ per device (which is weird since points should always appear in the same physical size).

If you want fonts to resize properly according to screen size you should use dp/dip instead.
So try this instead:
view.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSizeInIosUnit);
Now this might not be exacly the same but in my experience this gives the best results. If it doesn't have the proper size then figure out what size you need on Android as the base size and then go with that instead.

Related

changing display size of android app

My developed Android app works well on my phone, and I have used linear layout, and set the pixel as dp.
However, there is a setting in my phone, which can change the screen display size, I set it to large, and some of my layout is outside of the screen.
I tried to look up at the official document, but I found that it said usually setting change won't affect.
How can I resolve it?
You can create dimension xml file for different screen density pixels. Refer this link for more details
How to define dimens.xml for every different screen size in android?

5.2'' and 5.0'' screen support on android devices

I have been struggling with this problem about a week and can not figure out how to make it work. I have some views on a screen. And one values\dimens.xml(sw320dp-xxhdpi) resource file. Also I have nexus 5.2 1080*1920 420dpi and nexus 5.0 1080*1920 xxhdpi. The layout appears differently on both screens. How to make it display the same on each device?
What resource file should I add (if it is any)?
How to add for example values\dimens.xml(1080*1920 420dpi)?
I think your layout is simply built as poorly scaling. Unless you have some very specific use case, you need to make sure your layout fills the area it is provided with regardless.
As for the resource folder, if you want to make sure the same layout file is used on large screens, it is enough to put it in the folder layout-sw360dp. If you have xxhdpi devices with the resolution 1080x1920, Android will select the same file for both since the smallest side will be exactly 1080 / 3 = 360 density-independent pixels.
How to make it display the same on each device?
In general it's impossible for all Android devices. I think best solution - using VectorDrawable or SVG format and scale vectors for each device.

layouts designed in sketch software doesnt match when implemented in android

I have set a linear layout as 32 dp in sketch app using mac and when the same dimesnsions implemented in android studio and then i took the screen shot and imported to sketch app and when compared with the sketch designed measurements there was a huge difference in the height i.e the height was 44dp so can some help me out in this how to match exact measurements from sketch to android layouts.
I have faced this problem many times and found this solution which worked for me
In sketch first use the art-board which fits material design
for eg: 360 x 640
Get you design fit in height can vary and than try to export your design using zeplin, creat your android project using zeplin and export all your screens, zeplin will help you telling exact font, font size, images size also it allows to copy xml to be used in android studio and this give almost perfect result only difference while comparing is android bottom buttons and screens you need to adjust manually

android system is taking layout xml files only from layout-320

I am developing app.I have only layout folder with xml files,it is showing properly in more pixel screen ,but when i see my app in less pixel screen the text is big not same as more pixel screen As per android developer site, I came across layout-sw320dp ,layout-sw480dp. So I have added the xml files into layout-sw320dp,layout-480dp and made changes like text size and margin,then when i run them with sw-320dp in less pixel screen i can see text size same as more pixel screen,but when i run with sw-320dp the same in more pixel screen, the text is small ,it is taking layout from only sw320 actually it should take from layout folder.I d'not know where I am wrong can any one tell me.
screens with only layout folder
[![screen in less pixel density[![screen with more pixel][1]][1]][2]
screens with layout-sw320sp
[![screen in less pixel [![screen with more pixel density][3]][3]density][4]][4]
[1]: http://i.stack.imgur.com/6rTNw.png
[2]: http://i.stack.imgur.com/uHRkx.png
[3]: http://i.stack.imgur.com/qhcmk.png
[4]: http://i.stack.imgur.com/Z5PE0.png
You are not supposed to pick what resource size is shown, android does that depending on the device used at runtime. Your job is to set the resource in the correct folder for example res/layout/mylayout.xml and res/layout-sw480dp/mylayout.xml res/layout-sw320dp/mylayout.xml sw is smallest width of screen, 320 is a number, dp can be thought of as pixels. This concept of putting resources in folders with special names and allowing android to pick the most sutable special name/folder for the job works for any resource. Strings/languages, images/for device screen size,night/day,orientation-|.

Image compatibility in iphone and android

I developed UI for iphone apps and now want to use the same UI in Android apps. I read that Android use dip for image resolution and i also read that 1 dip=1.5 pixel.I simply multiply the image size by 1.5px. Now the problem is that the image is blur and not as clear as in iphone apps.So will some body suggest me how should i make a design so that it could be used in iphone and android.
dip is not simply the same as 1.5 pixels. A dip is a density independent pixel, and allows you to size items in a way so that they will look similar on displays with different pixel densities. When performing the layout Android scales the dip value depending on the pixel density of the device.
However, dip works best when sizing items which scale well, like the Android widgets. If you have an image you may want to always display it "actual size" so the image doesn't get scaled and become blurry - i.e. size it in pixels and not dip. So what you may have to do is supply a number of versions of each image so that you have a version that looks good for the screen densities on all the devices you choose to support. This is turn may mean producing a number of different layouts, depending on how you use your images.
I think it is not a big problem.You just copy your all images from drawable-hdip from drawabel-mdpi.It will work fine.

Categories

Resources