positioning items in android dev

核能气质少年 提交于 2019-12-13 00:24:14

问题


Hi I'm totaly new to android, I'm looking for a very very very simple thing that in every possible dev env is straight forward, except apparently android. how the hell do I set X and Y for every UI object that I wanna place there. For example in xml i have LinearView or RelativeView and in them I have Button, I'm looking for a way to set this button position on the screen using Y and Y, should be pretty straight forward thingy, I mean in iOS dev you just do CGRectMake(x,y,width,height) and there you go. What is the equivalent in android dev?

thanks


回答1:


From Android Developers

Android is designed to run on a variety of devices that offer a range of screen sizes and resolutions

So, unless you are targeting only one specific Android device, you'd not want to use absolute coordinates, as, for exemple, x=300px on one device can mean a reference outside the screen on another device(a small-screen one).
Instead, you learn to use just relative positions as top, bottom, below, etc, that works on every device.

Try to do the Hello Views tutorials first, in order to better understand how things are working for Android.




回答2:


Please use layout_x and layout_y with a AbsoluteLayout in your layout xml.



来源:https://stackoverflow.com/questions/5299551/positioning-items-in-android-dev

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!