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
Related
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.👍
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.
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.
I have a working widget that uses layouts and RemoteViews and scales itself nicely to whatever home screen area assigned to it. However, I need to display custom fonts and thus must re implement using an explicit bitmap and here is where the problems start, computing the bitmap size ended up to be a tough problem.
What is a good formula to compute the widget bitmap size in pixels as a function of these
values (and anything else that is available and is useful):
Number of home screen rows (R) and columns (C) allocated to the widget. (I derive min/max value in the widget_info.xml from these values).
Display metrics (screen size, DPI, density (D), etc)
Current orientation (O)
Android version (V)
The goal is not just to find a safe size but also not wasting screen real estate.
Just call getWidth and getHeight on the parent layout of your Widget. After the widget has been drawn once these values will be populated and you'll know the exact size of the widget.
I have recently noticed that layers can be resized when needed, so I'm trying to implement a method to resize the main layer to the size of the android screen where it is running.
How do I access to the device screen size from playn?
And there is another way to adjust the size of the game in android devices depending on the size of the screen with playn?
I believe what you are looking for is PlayN.graphics().screenHeight() and PlayN.graphics().screenWidth().
Copied out of the Graphics.java file:
screenWidth() - Gets the width of the available screen real-estate, in pixels.
screenHeight() - Gets the height of the available screen real-estate, in pixels.
width() - Gets the width of the drawable surface, in pixels.
height() - Gets the height of the drawable surface, in pixels.
As the descriptions state, screenHeight() and screenWidth() provide the actual screen height/width. With these values, you can adjust the size or scale of your game to fit the screen.
PlayN.graphics().width() and PlayN.graphics().height() give you the view size that you requested (via PlayN.graphics().setSize()), not the maximum available screen size.
To obtain the maximum available screen size, use PlayN.graphics().availableWidth() and PlayN.graphics().availableHeight().
Have you tried this?
This gives you the available device rendering surface.
PlayN.graphics().width()
PlayN.graphics().height()
Or I missunderstood your problem?