i'm new to android and android studio and i'm trying to build a relative layout.
when i choose a relative layout and try to put a for example button inside the layout it sticks to the top left corner of the screen, and the arrows for aligning the element do not appear on the screen and all choosen elements stick together at the top left corner of the screen.
how do you think i can fix the problem??
Considering the picture, you cannot "align" elements in design editor using RelativeLayout.
Look, you are probably talking about ConstraintLayout.
With ConstraintLayout you can align elements and constrain elements where you need.
https://developer.android.com/training/constraint-layout Check out this tutorial.
And also, currently not many people use RelativeLayout as it a little bit complex, has more performance issues than ConstraintLayout.
Related
I am struggling with an Android layout with ConstraintLayout and Barrier
https://gist.github.com/dscoppelletti/62130db0ed773712bdfe0128b27e327b
The widgets should be rendered vertically except for some pairs the should be rendered horizontally.
It is all right from the top down to the widgets txtAddress and cmdAddress.
The next widget lblEventCategories, instead of following below, is rendered at the top and then follows the next widgets just like I want.
I think the problem concerns the Barrier widgets, but I can't solve it.
For the TextView "lblEventCategories" remove the following line:
app:layout_constraintBottom_toTopOf="#id/txtEventCategories"
Constraining the top to the bottom of the guideline should suffice. This will move things on the right direction.
There may be other issues, but this is one. I recommend going back to the top of the layout and add items one-by-one and check it out in the designer as you go.
I have a ScrollView inside which I am using ConstraintLayout.
Now my ConstraintLayout has a lot of views inside it and user is suppose to scroll to view them (Obviously.) But I am using android studio layout editor and I am unable to place views beneath the views that are currently at the bottom.
What is the way around this issue? Other than I type them all in XML?
In design mode, you can drag and drop views directly to the android visualization panel, but if it does not fit, also you can drop them in the Component Tree panel.
You can set fix height to ScrollView, say 1000 or 2000 dp until your done with designing UI so you can add views at bottom.
Once done make it wrap_content
I am relatively new to Android UI. I always get confuse in providing margin to different view like should i provide bottom margin or should i use top margin(to view below it). Also should i use RelativeLayout or LinearLayout if both can solve my problem.
Thanks
It Depends on your need
Linear Vs Relative
If you just want to stack your TextView and Button horizontally or vertically you should go with LinearLayout.
If you want to make a layout that is more complex for example you can have an ImageView covering all of the screen and Button over the ImageView or if you want your layout elements to be stack on corners or at bottom, RelativeLayout is your Guy.
Top margin vs Bottom Margin
It doesn't make much a difference its a personal preference, I Use margin-bottom on first element rather than margin-top for second element.
One noticeable difference is when you are working with Show layout bounds during development. You can see here those pink coloration indicate that it is using margin on its view while padding has no coloration. Recently I prefer to use padding if applicable with my requirements as it seems more cleaner to inspect UI when Show layout bounds is enabled from Developer option.
The image is not mine and was just use as a quick sample.
If both Linear and RelativeLayout will solve your layout, then you should use Linear as it is faster to render.
With regards to top vs. bottom Margin. That's entirely your preference and how you want to think about the elements. Does Item A always sit 40dp above the next item or does Item B always sit 40dp below the previous item?
I am porting an iOS application so the design is pretty much out of my hand. What I have is two LinearLayouts, one with what is basically a bump (shown in pictures) that I want to overlap the second LinearLayout.
I get aesthetically what I want desire I use FrameLayout to contain the two layouts. However, here I run into two functional problems. The first, I need to be able to allow the bottom, overlapping LinearLayout which is composed of five adjacent image buttons to change size (preferably, using layout_weight). The second is anything that is in the bottom of the top LinearLayout it is hidden by the bottom LinearLayout.
When I switch to using LinearLayout, from FrameLayout to contain the two I get functionally what I want, however, aesthetically it smashes the button to fit.
Both cases are pictured. All feedback is appreciated. I am hoping to find a solution to this without designing a custom widget.
Thanks.
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.