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.
Related
I'm using a guideline to split the screen between two views in a certain point. I also need to put a CardView centralized to this same point. I constrained the CardView Top and Bottom line to the same point, the guideline, because it makes sense.
It seems to work, but I couldn't find any reference to this approach and also I found some examples using a different one: making a slightly bigger view to wrap the main view, and then aligning the bottom of the CardView to the bottom of this bigger view. Something like this:
<View
height="X+Y">
<View
id="#+id/view"
height="X">
</View>
<CardView
height="2Y"
bottom_toBottomOf="view"/>
</View>
So my question is: is it really supposed to work, or it just happens to work in my emulator?
Constraining top and bottom of a view to the same guideline to centralize it, is it supposed to work?
Yes, In order to vertically center a view to the edge of another (or to a guideline), you need to:
Constraint the top of the view to the edge/guideline.
Constraint the bottom of the view to the edge/guideline.
The same applies in centering a view horizontally to a vertical edge/guideline.
It seems to work, but I couldn't find any reference to this approach
Here is a source of that, in the Centring to the edge of a sibling in the editor Paragraph.
also I found some examples using a different one: making a slightly bigger view to wrap the main view, and then aligning the bottom of the CardView to the bottom of this bigger view.
This will work, but you have to define a predefined heights in layout, like you used X & Y.
My Idea is adding TextViews with rounded corners background to a horizontal LinearLayout, so if next one wouldn't fit - I will add TextView to another LinearLayout below.
Is there a way to do so? I know it sound like a custom view, but I would like not to bother as much - to adjust height, make click area calculations istead of simple clickListeners
Sounds like a recyclerview using a flexbox layout https://github.com/google/flexbox-layout with flexWrap turned on.
You could also use is in a static layout as well.
With flexWrap it does all the calculations to see if the "item" can fit on a line and if not starts a new line.
Many examples on the github page.
You could keep adding text views in linear layout while checking if newly added text view is outside of linear layout horizontal boundaries, if it is you could remove it from linear layout and add it in new one but I see no reason why you would want to do that.
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.
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?
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.