How to place UI elements to the position we want in Android? - android

I have some buttons, textboxes etc. in my android application, but when i drag them with my mouse in the xml file, their place doesn't change, or changes but they are not placed where i exactly wanted. How can i adjust their positions in the screen?
Thanks

Unfortunatly there is no such thing as absolute positionning in android ( RIP AbsoluteLayout deprecated since years.)
instead you have to position views according to their parents and according to other views in the same parent.
first you have to define wich parent you need ( if you want some viens in a single line go for a LinearLayout. a more custom layout: use a RelativeLayout ...)
then you can drag and drop views inside, but they will always snap a position relative to their parent and/or relative to the other views.
you can of course play with margins.
A list of layout type with some advanced techniques can be found on this page
Hope that helps.

You RelativeLayout as a group layout for your layout so positioning can somewhat easy using mouse.
Best is to arrange them from the xml code. Just Learn about using the Relative layout, LinearLayout and TableLayout

Learn how the XML works. For a LinearLayout, the items come in the order listed. For a RelativeLayout, the items are related by the values of their layout_XXX properties. Then you don't have to worry about the WYSIWYG tool not working.
FYI, the tool bundled with eclipse is extremely buggy. Don't count on whats on there being what's on your phone for anything non-trivial.

Like the others wrote it is easier to edit layout using xml editor. You can read more here http://developer.android.com/guide/topics/ui/declaring-layout.html.

Related

Android Studio UI

I am kind of new to Android Studio and I have been having lots of issues with the designer. I format everything in the drag and drop designer and then as soon as I press play and run the project, all the buttons and edit texts just bunches up in the top left corner. I've searched around online and it looks like I have to learn how to use linear layouts or relative layouts and XML. Can someone explain this to me or maybe point me in the direction of a tutorial?
Seems like the root element for the .XML file is a ConstraintLayout. You should read about LinearLayouts and then RelativeLayout to get started. To explain in simple terms, a LL uses a linear heirarchy to stack views vertically or horizontally amongst each other. A RL is used to position views relative to each other, ie, the position of one view depends on position of another view. ConstraintLayout is the latest and most powerful one, which is used to reduce deep nesting of views by defining certain constraints amongst views in the layout.
Also, for future question posts, please include code snippets which you think are causing the problem. It helps a lot. Cheers!

Using Layout - Android

I have a layout, but I need put more views (Buttons, EditText, etc), but how you know, the layout of the ADT is a bit small and I can't to set more views or know where is it, Somebody know How can I set more of these?
Thank you
Android isn't like iOS how you can just position elements with drag & drop.
RelativeLayout will position elements relative to each other and LinearLayout will lay out elements sequentially in a linear fashion, either vertically or horizontally. Both methods are better executed by actually writing the View XML yourself.
I suggest reading this: http://developer.android.com/guide/topics/ui/declaring-layout.html
If you want to actually see what you are adding to your layout without messing with the XML you could maybe change the device that the renderer is using to preview your layout.
I don't know what IDE you're using but in Eclipse and Android Studio you can change the device that your layout preview is rendered on. That way you can see what you're adding as you add it.
Then just make sure to put everything in a scroll view so users can access all the views and widgets you've put in that layout for your activity or fragment or dialog or whatever else it is.

How to decide which layout to use?

I have used both Linear and Relative layout . But still don't know excatly when to use which .
How to decide which one to use ? Explain with some example .
It's a personal preference for most of the cases.
You have to decide according to your necessity. You should however try to stick to RelativeLayout, if you are using multiple nested LinearLayouts since those can drop your performance noticeably.
See this tutorial. You'll have a good idea about different layouts. Hope this helps.. :)
This all depend on personal preferences and Experience matters a lot .
Personally i use combination of Linear layout in most of cases but sometimes FlowLayout and Relative Layout etc are used.
Linear Layout (vertical / Horizontal ) are used to create basic layout. Following properties help create view better and esthetic .
android:Layout_weight
Relative Layout is used to create overlay effect and also used to relate position of different Views according to position . Following properties help create view better and esthetic .
android:layout_margin
android:paddingLeft
android:paddingRight
android:paddingTop
android:paddingBottom
Frame Layout used to create Overlay layout like on option pressed etc.
also Frame Layout Can used to create overlay ads .
Grid Layout is used to create grid , you may have see gallery pics which are basically implemented in grid layout.
Example of Grid is Gallery Photos

Instructions layout for Android

I was looking into laying out some instructions on top of one of my applications like SoundHound does in one of their latest updates: http://i.imgur.com/D36nL.png
How is something like this achieved? Is this some sort of layout over another layout? Or a "dialog box" in a way?
You can create a frame layout with two children. The first would be the standard layout for the activity. The second would contain image views that display the help bubbles in the appropriate locations.
For more information see this: http://developer.android.com/guide/topics/ui/layout-objects.html#framelayout
Here is nice simple example: http://www.learn-android.com/2010/01/05/android-layout-tutorial/3/
You could just use a RelativeLayout with some elements having negative margins. They will overlap over other elements.

Aligning components at desired positions

Seeking help to design a layout as shown here:
http://docs.google.com/Doc?docid=0AQhgDtGvE2HgZGZ6cmtua185MTd0eGdyZmc&hl=en
The major challenge I face is aligning the components at desired positions. Please refer the three buttons(icons) and the way they are positioned.
Literally, going nuts, thinking how to position those exactly at the desired places.
Any help is much appreciated.
Regards,
Rony
Since you used the Android category, I'm assuming that you're trying to recreate this iPhone layout in Android.
The three buttons would probably be best laid as follows.
Your main layout container would probably be a RelativeLayout, so you can dock things to the top and bottom and lay everything else out in relation to one of its sibling elements. The three button icons (and I'm assuming you're referring to the circular buttons and not the tab bar buttons at the very bottom) would be in a LinearLayout centered within its parent (probably want to use gravity=center_horizontal on the main outer layout) and the individual items would have an equal left and right margin parameters to get the desired spacing (layout_marginLeft, layout_marginRight). You could also make the LinearLayout container of the buttons flush (layout_width=fill_parent) and using android:weight attribute on the outer buttons laying them out towards the center and using a lower weight on the center item. I'd favor the first option, personally.
If you're trying to create relatively complex layouts and any of the above doesn't make sense, go back and read the docs. Layout in Android is very powerful, but you really have to understand the available tools to take advantage of it.

Categories

Resources