Questions tagged [android-relativelayout]

Android layout that displays child views in relative positions to each other or to the parent view.

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).

RelativeLayout is a powerful utility for designing a user interface because it can eliminate nested view groups and keep your layout hierarchy flat, which improves performance. If you find yourself using several nested LinearLayout groups, you may be able to replace them with a single RelativeLayout.

This tag is to be used with more general or tags.

Useful links

3853 questions
490
votes
14 answers

Percentage width in a RelativeLayout

I am working on a form layout for a Login Activity in my Android App. The image below is how I want it to look like: I was able to achieve this layout with the following XML. The problem is, it's a bit hackish. I had to hard-code a width for the…
Sarson
  • 4,921
  • 3
  • 15
  • 5
302
votes
5 answers

How to programmatically set the layout_align_parent_right attribute of a Button in Relative Layout?

I have a relative layout which I am creating programmatically: RelativeLayout layout = new RelativeLayout( this ); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, …
Fahad Ali
  • 3,023
  • 2
  • 15
  • 4
280
votes
10 answers

Differences between ConstraintLayout and RelativeLayout

What is the difference between ConstraintLayout and RelativeLayout?
239
votes
13 answers

Defining Z order of views of RelativeLayout in Android

I would like to define the z order of the views of a RelativeLayout in Android. I know one way of doing this is calling bringToFront. Is there are better way of doing this? It would be great if I could define the z order in the layout xml.
hpique
  • 119,096
  • 131
  • 338
  • 476
238
votes
9 answers

How to lay out Views in RelativeLayout programmatically?

I'm trying to achieve the following programmatically (rather than declaratively via XML):
Dan
  • 2,389
  • 2
  • 14
  • 4
217
votes
4 answers

Can I Set "android:layout_below" at Runtime Programmatically?

Is it possible when creating a RelativeLayout at runtime to set the equivalent of android:layout_below programmatically?
AlanH
  • 2,191
  • 2
  • 13
  • 6
191
votes
5 answers

What are the differences between LinearLayout, RelativeLayout, and AbsoluteLayout?

I am confused about the difference between LinearLayout, RelativeLayout, and AbsoluteLayout. Could someone please tell me the exact differences between them?
148
votes
4 answers

Android RelativeLayout programmatically Set "centerInParent"

I have a RelativeLayout like this:
Alin
  • 14,809
  • 40
  • 129
  • 218
116
votes
5 answers

How to set RelativeLayout layout params in code not in xml?

For example I want to add 3 buttons on screen: one align left, one align center, last one align right. How can I set their layout in code, not in xml?
Qing
  • 3,029
  • 7
  • 25
  • 31
116
votes
5 answers

Is a RelativeLayout more expensive than a LinearLayout?

I've always been using RelativeLayout everytime I needed a View container, because of it's flexibility, even if I just wanted to display something really simple. Is it ok to do so, or should I try using a LinearLayout when I can, from a…
114
votes
8 answers

How to get RelativeLayout working with merge and include?

I have been trying for a few days now to make my layouts more efficient by converting from using several levels of nested LinearLayouts to one RelativeLayout and have come across a few problems that I haven not been able to find a workaround…
Justin
  • 6,564
  • 6
  • 37
  • 34
95
votes
4 answers

Equivalent of RelativeLayout in Flutter

Is there a way to implement something similar to what RelativeLayout does on Android? In particular I'm looking for something similar to centerInParent, layout_below:, layout_above:, and alignParentLeft For more reference on…
user3217522
  • 5,786
  • 7
  • 26
  • 34
95
votes
10 answers

RelativeLayout center vertical

I want to make a list row layout. This layout has a imageview in the most left, a textview right next to the imageview, and a imageview in the most right. I want all of them are center vertical.
user2368561
  • 963
  • 1
  • 6
  • 7
88
votes
9 answers

Issue with RelativeLayout when View visibility is View.GONE

I've a RelativeLayout thus: // <-- View.VISIBLE OR View.GONE Each TextView is anchored below the previous TextView with android:layout_below. The problem is that…
James
  • 3,729
  • 3
  • 20
  • 16
84
votes
9 answers

Android: show/hide a view using an animation

I've been looking through many google results / questions on here to determine how to show/hide a view via a vertical animation, but I can't seem to find one that's exactly right or not too vague. I have a layout (undo bar) that's below another…
1
2 3
99 100