Centering a panel on screen - basic4android

I've been playing with centering a panel on a device screen. I've tried a few things but cant get the syntax/math correct. I am adding the panel with it's size relative to the screen size as below (80% width and 40% height). At the moment I left the x,y location at 0,0 - Any suggestions on correct syntax to center on screen are appreciated!
Activity.AddView(quitsavepnl,0,0, 80%x, 40%y)

Here:
Activity.AddView(quitsavepnl, 50%x - 80%x / 2, 50%y - 40%y / 2, 80%x, 40%y)

You can get DisplayMetrics to get device screen and add it in the center of device screen if you want it.
Or if you want to display View in the center of parent View use CENTER_IN_PARENT, which is available in RelativeLayout

Related

Responsive in Unity 2D

I want my Unity 2d game responsive in all android mobile device. So i anchor 4 canvas to 4 edge (top left, top right, bottom left, bottom right).
But when i change a device, the size of each component is not change. Now i want the size of each component change depend on each resolution of device. What should i do or what tutorial i can follow.
Problem will come when i get small screensize, it like this
Canvas Scaler
You can solve it using Canvas Scaler.
You can find various options in the list in UI Scale Mode.
When selecting the option to fit the commonly used screen size,
If you want to align UI elements to the height, set Match, an element of Screen Math Mode, to Height, and if you want both height and width to match, place it in the center.

Setting X of camera's viewport causes the black strip to be rendered

I’ve run out of ideas, please help me.
That's the situation:
Imagine a simple object in the center of screen (it's always so, because camera has an orbit script)
Then we add a canvas image, 300px width, for example, on the right side of the screen (blue one in the picture). Our cube is not centered anymore.
For example, we can change X property of camera viewport rect, but we'll get a black strip and if object appears in this zone, it would not be rendered.
So, what can I do to offset camera position?
Thank you in advance!
The best option I have for now is:
create basic UI for FullHD resolution and make right panel as wide as black strip is
if user's screen bigger than 1920px, than change Canvas Scaler mode from Constant pixel size to Scale with screen size

How to change canvas' size in unity3d

I can not change canvas' size when it's in Screen Space - Overlay Mode; After some research I found that the size of a canvas is determined by your game's screen size. The canvas just covers your screen. So I think I could change my camera's size to change canvas' size. But it does not work. Does anyone know how to set a specific size to a canvas?
So may be my question should be how to change the screen size showed
in editor?
To change the screen size, go to the Game window (accessed by the menu "Window->General->Game"). At the top of the window will be a screen size menu (outlined in green, below) to change the screen size. When pressed, it will display the list of screen sizes that will be emulated. I say "emulated" instead of "displayed" because it is possible to have a screen size larger than the screen on which you are working. It is also possible to zoom into a screen. The "Scale" slider (to the right of the screen size menu) will allow you to scale up/down.
As a note, the list of screens and resolutions shown are related to the current build target (accessed by "File->Build Settings..."). For example, common iOS screen sizes are displayed in the list when the build target is iOS.
Use the Canvas Scaler Component
Unity3D Documentation: Canvas Scaler

Unity - Keeping UI centered no matter the screen resolution

I want to keep my UI looking the same no matter which resolution the screen is at I am running of 16:10 in my game view and I want the UI to stay the exactly the same and centered even if the screen resolution changes.
Screenshot of UI
For the UI in the screenshot, I assume you want it always at the bottom of the screen and always the width of the screen.
For always taking up the width of the screen, select your canvas and go to its canvas scalar component. 'Change UI Scale Mode' to 'Scale with Screen Size' and adjust Reference Resolution to a resolution that looks good for you. Then the canvas elements will be the same width on all resolutions.
For always staying centered at the bottom of the screen, select the UI elements themselves, or their parent if they have one. Change their anchor to bottom center.
For more information about how to design for all screen resolutions, check the documentation as Hellium suggested!

Image View - Aligning image in centre on all devices on launchscreen

I'm new to iOS development. I'm trying to add logo on launchscreen in centre. I've a background with gradient colour so I've used a png file and stuck it in the background.
Next is logo which I want to centre for all devices.
I've two part questions
1) Is there anyway I can specify the constraints so that it is applicable to all devices? Example specifying top and bottom constraints in % ?
2) If above is not possible then how do I align logo in centre so that it works on all devices? Do I need to apply constraints separately on all devices?
I tried to set the width and height separately for all devices but it modifies dimensions on other devices. Not sure if this approach will work or I'm doping something wrong?
I'm aware that in worst case that I can just create launchscreens with logo in it as png and stick them for each devices separately which will work. I just wanted to know if it can be done with constraints.
Tx
As you suggested I added constraints to align it in centre horizontally and vertically. It seems to be good on one device but on other it's not. Please see images below.
And then how do I change image size?
One device
2nd device
You do have centerY and centerX constraints.
In storyboard, select the imageView that you have already added to your view. Right-clic drag to the main view (full screen view) in the left panel and choose center horizontally, repeat with center vertically.
You will need to also set the width and height constraints of your logo.
ALTERNATIVELY:
You don't need to clic drag, you can add the center constraints in the "add new alignment constraints" tab.
Finally I manage to solve what I Was looking for thanks to all those who helped. It was good learning period, 2 days in total ;)
Step 1: Align image to centre vertically and horizontally.
Step 2: Scale logo to fill the space. Please follow this video which is bang on point what I was looking for.
http://roadfiresoftware.com/2015/04/how-to-scale-an-image-view-based-on-device-size-with-auto-layout-in-interface-builder/