Displaying same font size in any Android screen - android

I want a text to have relatively same size in every Android device.
I have a canvas (fullscreen). In middle of this canvas is some text. This text fills 20% of my screen leaving 40% for both sides. I want these precentages to be true when text is viewed in any Android device.
I also want the same thing vertically.

Put the size into a Dimension resource using “sp” units.

I decided to measure width of text in pixels and save that value.
When text is loaded in different resolution, I multiply the original pixels with scale of resolution change. I loop up from text size one, always calculating new resolution and checking which matches the original resolution best.

Related

How do I ensure my UI buttons scale with screen size and orientation using unity?

This might be a dumb question but I'm using unity to build a double pendulum app and because not all screen sizes are the same the UI buttons get moved around and don't scale to match the phones screen size. I attached a few images to show you what I mean.
Notice how in the third image, the return button overlaps the other UI sliders. I think the issue is that the pixel distance from the top of the screen doesn't change given new orientation. Is there a way to keep the spacing proportional?
On your canvas object, set it to Scale With Screen Size then, set the Match property to 0.5. This way the canvas will scale with both width and screen height.
If you need more info about Designing UI for Multiple Resolutions, check here
Well in your parent cancas object in the inspector,the 2end setting there a a drop down. Click it than a magical setting scale with screen wil be ther.👍

Does View have the same amount of dp on every screen?

I want to make a background for a View (LinearLayout specifically) and I want it to look good on every screen so I would like to make separate .png background files for every screen density and put them in their "drawable" folders.
But how to measure view's size on every screen to make proper background files? Is it a good way to take view's size in dp on one screen and then calculate its size in pixels on every density according to this dp value?
My LinearLayout for which I want to make background is made of a few TextViews groupped vertically. Lets say that text size will be in dp, not sp. Will this view have the same size measured in dp on every screen configuration?
cut your background .png images according to your need that will be better for you. if you set the size of them the image gets blur.

Android create semi resizeable box

So basically I have 3 boxes on screen, each displaying different information regarding audio frequencys.
The top box shows the Note, Middle shows the pitch of that Note, and 3rd shows your pitch.
I wanted to have the numbers in a box, and since they constantly change, I wanted the box to remain a certain size instead of constantly increasing in size to fit the text. However, I also don't want to give the boxes a specific size as I want them to be able to resize depending on the screen size.
Is there a way to do this easily? Or would I have to create separate XML files for each device or something?
I will attach an image so you can see what I mean.
Image: http://i.imgur.com/5NVR54N.png
So just imagine that each box is resizing itself depending on what text is placed in the box.
Any help with this would be great thanks!
If "So just imagine that each box is re-sizing itself depending on what text is placed in the box" this is needed then in the XML for the TextView widget that you use for displaying the values use.,
android:layoutWidth="wrap_content", android:layoutHeight="wrap_content" . The wXh of the view would be adjusted according to the content (values) .
If "I wanted the box to remain a certain size instead of constantly increasing in size to fit the text." -If this is not done, that is if you have fixed width text widgets, then the text will be clipped if they exceed the max width.
2.1 By above if you mean same size on each device, then figure out the maximum possible width/height on a mdpi (320X480 mdpi) emulator for each textview, say 100px width and 80px height and is what suits you for the Note, then in the XML for the TextView widget for Note use android:layoutWidth="100dp", android:layoutHeight="80dp" where "dp" would give you device independent pixel size, meaning the size will be adjusted according to the screen density on which the emulator is running.
http://developer.android.com/training/multiscreen/screensizes.html and related material should help.

Android home screen widget size in pixel

This is on Jelly Bean, and so the widget can be resizable by the user. The only thing in my widget is an Image View. I am creating a bitmap whenever the widget updates which I set into the Image View itself via remote views. The bitmap created and drawn changes depending on the size of the widget, and the space taken up by it.
The problem I have is in determining what size to create the bitmap which I understands must use pixels. Is there a way to find this out from the widget provider? Either the space available in pixels or dips will be fine as I should be able to work it out from one to the other.
The size in dip of a widget can be calculated using the following formula: 70 × n − 30 where n is the number of cells in either width or height.
You can convert dp values to pixels depending on the screen density.
Read more at: http://developer.android.com/guide/practices/ui_guidelines/widget_design.html

Adjusting Font Size to Fit, Paint.measureText returns too small a value

I'm using the FontFitTextView that was posted in this other thread, but it isn't working exactly right for me. The measureText() call is returning a number that is obviously too small to display the string. When it runs through to find a font size that will allow the text to fit, the font size it settles on is still too big. I feel like there is some other kind of padding or margin or some other invisible that is contributing the math that makes up the width which is causing the discrepancy.
For example... I want to set the text of my FontFitTextView to be "10,000.25"
The width of my FontFitTextView is 96 pixels, with 8px padding on both sides, so my available width is 80 pixels. The call to measureText() says that the text "10,000.25" is 64 pixels wide. This means that the current font size should be small enough to display the entire string. However, when the string is actually drawn on the TextView the last 2 characters are chopped off and all I see is "10,000." instead of "10,000.25"
Any ideas?
It turns out the problem was related to the emulator. I provisioned my app to my android device and the FontFitTextView worked as intended.

Categories

Resources