I'm just putting the finishing touches to my Android app. Unfortunately, I dug straight into development without reading the documentation and built my layout with AbsoluteLayout and it turned out to look terrible when I loaded the app on my phone. Now I'm redoing the UI in a RelativeLayout and I want to put empty canvas space in between my ViewGroups in the y-direction. I am currently achieving this by putting random TextView sentences that are of the same color as my View's background in order to make psuedo-empty space. Is there a better way to do this, because right now when I define a specific ViewGroup to be placed below another View, it gets stuck right below the top View.
As I was writing this, it dawned upon me that using padding might be the answer.... Any other suggestions?
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 or center).
ConstraintLayout has flat view hierarchy unlike other layouts, so does a better performance than relative layout. Yes, this is the biggest advantage of Constraint Layout, the only single layout can handle your UI.
Android RelativeLayout enables you to specify how child views are positioned relative to each other. The position of each view can be specified as relative to sibling elements or relative to the parent.
For each view in your xml layout, you can apply the android:layout_margin* where * is Top, Bottom, Left, or Right. You will also want to make sure to use dip units so it spaces the same on different displays.
One thought, you might want to be careful of using margins and padding to get it to look like you want, because phones like the droid with a taller screen than "standard" can really mess things up.
I suggest looking into placing frame style elements in their position using layout_alignParent* (Top, Bottom, etc.) and then, if, for example, you have a box of open space on the screen, align its corners with the framework elements which will be located correctly because of the parent alignment, and then use a sub LinearLayout that is centered (android:gravity="center_horizontal") for the interface buttons or whatever.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With