Possible Known Issue with Eclipse Layout Builder? - android

I'm building a layout within Eclipse for Android using the RelativeLayout. I lay down a simple stack of buttons one on top of each other. For some reason the button snaps to the first button position even though I clearly place it down on the last stack of buttons. I try everything to move it to the right position eventually I just let the layout builder stick it to the bottom of the screen edge.
When I try this view inside the app, the last button is magically snapped to some random spot usually near the top. Obviously incorrect. As a hunch I tried it again but I left it alone this time, when I laid the last button down again ( which within Eclipse Layout builder its snapped to the first elements position for some crazy reason). Surprisingly within the app itself it appears in the proper location. So this must be a bug with the Layout builder itself.
It looks horrible in Layout builder (almost unusable) and the position of UI elements totally wrong, is this some known bug with Layout Builder + Android or do I need some update or new SDK or something?

There are many reported complaints about the ADK Editor for Eclipse, but one alternative is to try DroidDraw
http://www.droiddraw.org/
The preference of some Android developers is to directly modify the XML. This often provides more flexibility as you can see the exact rules that are defined for your UI.
If you are looking at just stacking Buttons on top of each other, you may want to consider a LinearLayout.
http://developer.android.com/reference/android/widget/LinearLayout.html
This is a layout that arranges its children in a single column or a single row.

Relative layout every "view" is positioned relative to something else. It would help you to understand better if you look at the xml. You will see what each item is aligned on. It is difficult to get this layout right as you see especially when you design in eclipse and run on an avd or real device. Consider placing a linear layout inside the relative layout and your buttons in that. This way your button group is together in a row or column and next to this you could have text or something.hard to explain but group like things together and nest layout inside other layouts.frame layout only one item is viewable at a time,like pages in a book or slide images. I hope I explained this good. I have no idea why you would do buttons that way.absolute layout is x,y positions where you put it is where it stays. Like that's gonna work. Try a different screen density and things are bunched up in the corner.like I said the key is nesting the layouts

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!

iOS: Relative Positioning like Android's layouts

Is there any way position views relative to each other like you can with Android layouts?
Example: You have two UILabels that are dynamically set to strings of variable length, one above the other, and you want the bottom label to appear directly below the last line of the top label, regardless of how many lines the top label ends up having.
Another example: Same situation as above, but one of the labels is sometimes hidden. You want the resulting label(s) to be centered vertically in the parent, regardless of whether it's one label or two labels.
Android's Linear Layout and Relative Layout make this very easy to do, but I can't figure out how to do this is iOS. Can it be done?
You will be able to do this using AutoLayout in iOS6. For an application that should run in iOS before 6.0, you have to do it by yourself, but this is not very complicated.
Actually I have implemented a class to do this (that's a long time ago, I hope it still works, but there is no reason not to). This OHStackView class is a subclass of UIView that automatically layout its subviews horizontally or vertically to stack or align them.
You can ask OHStackView to stack its subviews horizontally or vertically (one above the other, etc), or align their top/bottom/left/right borders or their centers, and even specify a padding between each subviews. Each time one of the subview changes its frame or size, OHStackView will automatically relayout all depending views to realign everything.
(E.g with your two UILabels, a simple call to sizeToFit on your labels to make them adjust their size to their content will relayout everything around automagically)
There is an example project provided so feel free to test it.
Note: IIRC, my subclass does not take the "hidden" property of the subviews into account. But you can easily add support to this behavior by adding a condition like if (v.hidden) continue; in the for loop of its layoutSubview implementation to only take non-hidden views into account in the layout algorithm.
HTH
I've been searching if it's possible for a long time. As far as i can tell, it's not possible for now. I don't remember where i read this,but it will be possible with ios6. Instead of using Android's Linear Layout,you can use sizeWithFont method to detect size of your UILabel,then you can set their frame to position them.First,you need to set their text of course to find their size according to their font family. Another thing you can use is sizeToFit method. Unfortunately,i don't know how to use it. You can give a shot,though. At that time,i found this.Maybe ,you can use it https://github.com/scalessec/CSLinearLayoutView

Which layout can provide free drag and drop insertion?

I'm using Eclipse graphical layout, and i want to Drag and Drop components to the layout and i want them to stay at the exact position that i dragged them.
Relative Layout is the closet thing but it changes the location of the components after couple insertion.
thanks.
Rami.
i want them to stay at the exact position that i dragged them.
No, you don't. Android devices come with screens in many different sized and resolutions, so fixed positioning of components is a recipe for making the application unusable to users with a different screen that you.
The point of layouts is that they can adjust to different screen sizes. Learn to use them properly.
You're looking for AbsoluteLayout, but it is deprecated.
RelativeLayout is the way to go, just pay some attention to the hints drawed on-screen when you place your elements.
You should be careful also to avoid circular references otherwise your items will be scattered randomly over the layout. (Example: Textview A on right of TextView B; TextView B on left of TextView A)
Be careful also when you change your element's id because the IDE does not update automatically all the references and thus your layout gets scattered again. When you update an ID you must update all its references in the XML file by hand.
Actually absolute layout is the answer what u want ,but that is deprecated.Relative layout does what you want.But it arrange its child based on parent position.If you drag a text view ,then other view will depend on this text view.If you have inserted 2 view,then third view will depend on the parent(2 views).But in between if u disturb any of the view ,it may affect other views.So do things systematically
In Java what we can typically use is GroupLayout. You may see what the equivalent is for android.

Problem with Android drag - drop UI development

I am newbie to android so this might be one of the dumbest question you face.
I am developing UI in Eclipse through drag-drop.I have added many elements in one screen now
the window where you drag-drop UI elements is not growing/scrolling beyond a capacity.
So I am not able to see newly added elements.
Please check image for more details..
You can observe elements after Storage Position are not visible.
How to check other elements or cant we add elements beyond a certain number/size ?
~Ajinkya.
You can add as many elements as you want. I can see a bunch of LinerLayouts for each of your items, but each linear layout is one row and has a horizontal orientation, correct? I'm not sure what you have as your overlying view, but make sure that all of those items are inside of a LinearLayout with vertical orientation. You can wrap that in a <ScrollView> to add a scrollbar to it. Here is a Scrollview example
Side note: Also, the drag and drop is nice to look at, but I've always had a better experience directly editing the xml, even if I started creating the layout with the GUI. It's easier to tell what is going on with each element and make changes. It's best to check the way everything looks in the emulator too, sometimes it can look different than in the GUI editor, especially if items are put into your interface programmatically.

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