0

After reading the very helpful answer here: Why does LayoutInflater ignore the layout_width and layout_height layout parameters I've specified?, one thing I would like to add is to have a button (or any other View for that matter) be placed at a specific point on the screen.

Community
  • 1
  • 1
Mike D
  • 4,938
  • 6
  • 43
  • 99

2 Answers2

2

You can use FrameLayout and specify margins for objects using parameters android:layout_marginRight, android:layout_marginBottom and so on. This will help you to set view position relative to the parent view.

You can also use AbsoluteLayout, but it is discouraged to do so. AbsoluteLayout was used when Android was supposed to work with the screens of a fixed resolution, and when this changed with Android 1.6, AbsoluteLayout became deprecated since it is inflexible and can't work properly on screens with different resolutions.

Malcolm
  • 41,014
  • 11
  • 68
  • 91
  • I had thought about declaring margins in the XML source, but I am aiming for maximum re-usability, specifically, there are multiple places on the screen where these could be placed. I would like to be able to set the position relative to an arbitrary point on the screen. – Mike D Oct 28 '11 at 19:23
  • But when you position your view relative to the boundaries of the parent view, aren't you achieving the same thing? If you really need absoule placement, then AbsoluteLayout may help you, but as I've said, it's going to be problematic to use it because of the screen diversity. – Malcolm Oct 28 '11 at 19:28
0

Hi you can use AbsoluteLayout for positioning a view to a particular location if you know the coordinate of the view.use this link for the overview of available layout. http://mobiforge.com/designing/story/understanding-user-interface-android-part-1-layouts.

mathlearner
  • 7,509
  • 31
  • 126
  • 189
  • I could use an AbsoluteLayout, but as mentioned above it is deprecated, and I would like to future proof the application as much as possible. – Mike D Oct 28 '11 at 19:24