简体   繁体   中英

Android UI based on top and left property

I was working with Android UI in Eclipse and found it to be bit hectic. Designing layout using layout managers is bit time consuming. So i was wondering whether it is possible to specify the position of the UI elements based on (x,y) system ie top and left property which is widely used in Visual Studio IDE for VB,C# etc ?

Positioning element based on top and left property would provide much flexibility.

How would that be flexible? Yes, doing layout correctly takes time, but if you do it right, it will scale properly to any screen size. If you're using X/Y coordinates, you will be hardcoding to a specific screen size, which is an especially bad idea on Android (as there are a multitude of screen sizes available).

If you need x, y positioning, you can use a FrameLayout with foregroundGravity set to top|left , and use layout_marginLeft for the x value, and layout_marginTop for the y value.

You can use AbsoluteLayout and suppress deprecation warnings in your code, but think of how will it look on different screen sizes?

I would advise to use RelativeLayout in your case.

As far as I know, there is no built-in layout that is based on (x, y) coordinates. You might be able to find 3rd party libraries that can do this for you. However, I'm skeptical that they will provide satisfactory results. Remember that Android is deployed on a wide variety of devices which include a range of different screen sizes and resolutions. This means that you can make the UI look pretty on one device using specific coordinates but it won't look very good on other devices.

Personally, I edit my UI layouts directly in the XML files. I find that this provides me better control than using the Eclipse UI editor. You still have to learn how the layout managers themselves work.

Android tries to ensure that your layout components are arranged nicely so that they:

  • don't overlap with each other
  • don't go off the screen space
  • look similar on different screen sizes
  • etc

It gives you nice XML Attributes to help you arrange your layout. I would recommend you use RelativeLayout for this application, because it allows you to put your layout components in positions RELATIVE to each other.

Some XML attributes you can specify are given here: Android Reference, RelativeLayout.LayoutParams

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM