Android: Adding a Button at a Specific Location - android

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.

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.

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.

Related

Certain Options Missing in Android Studio

enter image description here
Absolute beginner here, and I can't seem to access all of my options in android studio. For example, when I put in a textview in the layout, for the layout_width, fill parent option is not appearing, even though I definitely remember it to have been there when I used in briefly on my friend's computer.
It's not there as it's not an optimal option:
Important: MATCH_PARENT is not recommended for widgets contained in a
ConstraintLayout. Similar behavior can be defined by using
MATCH_CONSTRAINT with the corresponding left/right or top/bottom
constraints being set to "parent".
(source)
maybe you saw that option on a different layout (eg. linear).

All objects move when I drag one around

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.

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.

How to use combination of Layouts to get widgets at desired position

we are confused with designing interface file for android,we have made user interface with Absolute layout and used "dip" instead of "px" (for different screen size issue) ,but it looks like,Absolute layout has been depreciated,and developer.android, recommends not to use Absolute layout
So other option we have is to use
1.Linear layout
2.Frame layout
3.Table Layout
But we are unable to bring Combination of above layouts so,that we can make button/widgets to proper position we need
How do we make widgets to desired position of screen with above said layouts and making them compatible with different screen sizes we have in android devices
would like to get a generic answer about same,
Tools used are: DrawDroid
The best layout to use if you were considering an AbsoluteLayout is a RelativeLayout.
Check out the Android Common Layout Objects page and its explanation of how to use a RelativeLayout.
Without more information on what you are trying to do, expanding this answer anymore is useless.

Which layout do you suggest

Here is a video of my app:
It's currently using absoluteLayout, and since absoluteLayout is deprecated i decided to change my layout.
So what Layout do u suggest using for this app?
Please see the part of the video, that the game has started, that's the only part with absolutelayout.
Thanks
It really depends if you want your UI to flow in a linear fashion or not. The majority of the time I use RelativeLayout with some instances of LinearLayout here and there. Relative seems to me the most flexible for me.
"You can achieve much the same layout by using a FrameLayout instead, and setting layout_margin attributes of the children. This approach is more flexible and will yield better results on different screens."

Categories

Resources