All objects move when I drag one around - android

I am creating an Android app in Eclipse, but when I drag around a TextView, everything below it moves around as well.
This is when I haven't dragged anything.
http://i.stack.imgur.com/Twp4L.png
This is when I drag the TextView just a bit.
http://i.stack.imgur.com/oJ75k.png

The layout designer doesn't work very well in Eclipse. You could try Android Studio's layout designer (the new early access preview), that one is a bit better, but not by much.
The most common practice is to use the layout designer to only get started with and perhaps to use the Outline view panel to tweak some of the nesting of the layouts/views by dragging some of the nodes inside it, but then it's to dive directly into the xml code yourself. There is really no other substitute for doing that. The tool just isn't very good yet.

This is called a Relative Layout. In this case, the components are placed relative to the TextView, which is not so unexpected. It depends how you set relations in the layout XML. What layout you want to achieve?
You can either set that all the components are placed relative to the whole view, or use some specialized layout types like LinearLayout. It all depends on the effect you want to achieve.

Related

Why android studio automatically reorders views and elements in graphical layout editor

I was curious about knowing that why this happens in android studio when I'm trying to graphically edit layouts. Every views and attributes are reorganised. is there any rendering benefits or any benefits at all?
Because its not a drag and drop editor. Not really. You're putting children into a parent layout, which works on certain rules. When you drag children around, you change the rules but you're never putting it in a particular place.
I really, really, really suggest you don't use the graphical layout editor. Its confusing, not very accurate (especially if using custom views) and inefficient. Learn how to write layout xml, you'll be much faster and write easier to maintain layouts. Most pro devs don't use it at all.

Android Studio does not show anchor points when laying out a custom component in a ConstraintLayout

I've developed a super simple custom View in Android, to be used as a generic placeholder, that just shows a diagonal line between the upper-left vertex to the lower-right one.
The problem is that when I try to lay out it in a ConstraintLayout, the editor does not show the anchor point I would expect. An image is worth a thousand words:
If you're experienced with Android Studio you know that if I were using a standard View, like a Button, instead of mine custom View, the green arrow should normally hook to the grey "BUTTON", representing a vertical constraint.
Any idea why Android Studio does not behave as expected ?
It is an Android Studio bug or maybe my custom view misses something else like some callback method ?
It is worth to mention than if I manually edit the layout XML writing the proper contraints and then I reopen the view, it is shown correctly, with all the arrows representing contraints in place! Even the one that I was not able to draw in the first place.
Ok, the answer was quite easy. In order to properly work, it is mandatory to assign an android:id to all components. If some components involved in a ConstraintLayout do not have it, it is impossible for Android Studio to set such constraint. This is because a constraint has this kind of form:
app:layout_constraintTop_toBottomOf="<ID OF THE COMPONENT ATTACHED TO>"
So... in my case it was enough to ensure all components, be them custom or default ones, have an ID.

Android XML Layout or Java Coded

I am starting to delve into Android Development and there is a lot of material online. The question is... What are the pro's and con's against the drag and drop XML design method vs coding the view manually? The only reason I ask on here is because online the views are mixed and they don't really back up what they're defending.
If I use the drag and drop method will I have issues further onto my development adventures? That is the thing that worries me the most... I don't want to learn the drag and drop method and then editting the XML to cater for my needs and then be handicapped by it.
For the beginner(s), I highly recommend not to use Drag and drop. We need to understand XML, to be comfortable with android widget. Understanding XML will come handy in future when creating custom styles and themes.
Here are few pointers before you dive in android XML layout
Try sticking with match_parent and wrap_content while defining android:layout_height or android:layout_width if possible
Make sure you have good understanding of RelativeLayout, LinearLayout and FrameLayout and how its child views are arranged.
Forget about ConstraintLayout, AppbarLayout and similar advance layout at current.
Try exploring TextView, EditText, Button, ImageView and ProressBar as far as possible.(This are most common widgets/views)
Try avoiding any tutorial related to ListView, its deprecated. Try using RecyclerView instead, it is one of the important widget that would be used in regular basis.

How to disable auto alignment?

I'm building an android project and I'm using eclipse.
I just can't figure out how to disable the annoying auto alignment.
I just want to place buttons wherever I want to drop them on the GUI interface but it just keeps
to align them one to another. I've tried to delete those alignment lines in the xml code
but it still brings them back as I move the buttons on the GUI interface.
Is there an way to disable that function?
Thank you,
Alex
Is there an way to disable that function?
Not in a way that you will find satisfactory, I suspect.
You have not really explained what the "alignment lines" are, so we are forced to guess. My guess is that the "alignment lines" are because you are working with a RelativeLayout container. Quoting the JavaDocs for RelativeLayout, RelativeLayout is:
A Layout where the positions of the children can be described in relation to each other or to the parent.
And, quoting the guide for RelativeLayout:
RelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout area (such as aligned to the bottom, left of center).
Hence, the "alignment lines" are there, and are replaced by the GUI builder, because they are the point behind using a RelativeLayout container.
Of course, you are welcome to change the container that you are working with to something else.
However, in general, Android does not really support very well your stated objective ("I just want to place buttons wherever I want to drop them on the GUI interface"). Just as you don't do that in Web development, you don't do that in Android development, and for much the same reason: you need to take different sizes into account (browser window size for Web, screen size for Android). RelativeLayout, LinearLayout, TableLayout, and GridLayout are all designed to have you specify widgets plus rules for positioning and sizing, so that you can design a UI that will accommodate the difference between a 3" and a 4.5" screen, for example. This is akin to using HTML tags and CSS rules to define content and its positioning in a Web page. Eclipse's drag-and-drop GUI builder for Android can assist in your definitions of these rules, as you are perhaps seeing with your "alignment lines" for RelativeLayout.
I think I may be able to help. If you set your layout to Relative Layout you can drag and drop any of the views wherever on the eclipse GUI.

Alternative to AbsoluteLayout in "multi layer" layouts

I am developing an android app with a layout that includes buttons arranged around a circular element. As the corners of said element would overlap with other buttons, the recommended layout types (LinearLayout etc.) are not a viable option.
However, I want to do this right and not use the deprecated AbsoluteLayout. So far, though, I see no alternatives. Are there?
Relative layouts would probably work depending on how you want to place your buttons.
It allows you to place the buttons to the left/right of each other or above/under, so placing them around a circular element should be possible.
Here's the link to the android documentation for relative layouts.

Categories

Resources