Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Giannis7312777 · Aug 05, 2013 at 11:13 AM · androidpositionresolutionheightwidth

Same button position in all Android devices

Hello everyone, my problem is that I can't configure out how to adjust a button in the same position in all android devices. I use Screen.width and Screen.height with variables like, Screen.height / 2 - x etc... Is there any way to do it?

Thanks in advance. Any help is appreciated :)

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ahaykal · Aug 05, 2013 at 12:24 PM 1
Share

Hello well what i use is the scale and height with respect to width and height of the screen. For Example: GUI.Button(new Rect(Screen.width/2,Screen.height/2, Screen.width/8, Screen.height/8),"Hello");

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by robhuhn · Aug 05, 2013 at 02:23 PM

If you want to use dp instead of px you could use that script "DisplayMetricsUtil" http://answers.unity3d.com/questions/337460/scaling-gui-buttons-to-be-the-right-size-no-mobile.html

The script provide some extension methods for converting dp to px and px to dp:

 if(GUI.Button(new Rect(Screen.width - 110f.DpToPixel(), Screen.height - 30f.DpToPixel(), 100f.DpToPixel(), 20f.DpToPixel()),"MyButton"))

No need to convert Screen.width because it's the full width of the device.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
2

Answer by Joyrider · Aug 05, 2013 at 01:30 PM

You seem to have given the answer yourself.. and ahaykal gave an example of what you said...

Just another exemple taking into account the button's size: If you'd want a button to always be at 5 pixels from the lower right corner and your button was 100x20, you'd write (in c#):

 if(GUI.Button(new Rect(Screen.width - 5f - 100f, Screen.height - 5f - 20f, 100f, 20f),"MyButton"))
 {
 }

You could also add a resizing factor (horizontal screen width for exemple) to resize your buttons. If your base resolution would be 1024x768 for exemple you'd write

 float factor = Screen.width/1024;    
 
 if(GUI.Button(new Rect(Screen.width - factor *5f - factor *100f, Screen.height - factor *5f - factor *20f, factor *100f, factor *20f),"MyButton"))
     {
     }

The button would always be in the lower right corner and it's size and distance to the border would be proportially changed to the horizontal resolution of your screen.

On a 2048x1536 (ipad retina) or 2048x768 (doesn't exist) screen, your button would be twice as big and twice as far from the border (10px)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Game fills only one quarter of the screen, why? (Android) 1 Answer

Object resolution 0 Answers

Keep screen width instead of height for resolutions 1 Answer

Is it better to enlarge an image by width/height or by scale? 0 Answers

Screen width and height, how to bypass?! 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges