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
78
votes
2 answers

What is the baseline in RelativeLayout?

What does "baseline" refer to when used in the context of a relative layout? Simple question, probably, but the documentation and google offer no hints.
David Liu
  • 9,426
  • 5
  • 40
  • 63
78
votes
2 answers

remove rule from RelativeLayout before api 17

Prior to API 17, how do I remove a rule from a layout? I have a RelativeLayout with a number of children. The RelativeLayout is the main layout of my activity. After adding the rule programmatically using RelativeLayout.LayoutParams layout =…
Cote Mounyo
  • 13,817
  • 23
  • 66
  • 87
76
votes
7 answers

Overlapping Views in Android

Is it possible to have overlapping views in Android? I would like to have an ImageView with a transparent png in the front and another view in the background. edit: This is what I have at the moment, the problem is that the image in the imageView is…
Alexander Stolz
  • 7,454
  • 12
  • 57
  • 64
73
votes
11 answers

Android: Align Parent Bottom + Bottom margin

I've used a relative layout and I want to set the button at bottom of the screen, However this puts it all the down to the bottom and I would like to have some margin so it there's some space between the end of the screen/view and the button.…
Jacob
  • 3,521
  • 6
  • 26
  • 34
71
votes
3 answers

How do I programmatically remove an existing rule that was defined in XML?

I have a linear layout that is contained inside a relative layout. It is set in the XML file to be to the right of another linear layout (this works fine). In some cases I want to change the relative position of the layout during the onCreate of…
71
votes
3 answers

How to create a RelativeLayout programmatically with two buttons one on top of the other?

I'm adding two buttons to the UI, but they appear on top of one another. I want them to appear next to each other. What am I missing in this code? m_btnCrown = new…
Karthik Murugan
  • 1,429
  • 3
  • 17
  • 28
71
votes
2 answers

LinearLayout vs RelativeLayout

What are the advantages of RelativeLayout over LinearLayout in android ? For a particular design which one would you prefer and what's the reason behind of that ?? Is it(RelativeLayout) comparable or similar like HTML
??
65
votes
2 answers

How to add a view programmatically to RelativeLayout?

Can you give me a very simple example of adding child view programmatically to RelativeLayout at a given position? For example, to reflect the following XML:
Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385
60
votes
1 answer

FrameLayout vs RelativeLayout for overlays

I need to implement an overlay (translucent) screen for my app, something similar to Showcase View My guess was to use FrameLayout for this usecase, because it is used to stack items on top of each other. But I was surprised to see that the above…
dev
  • 11,071
  • 22
  • 74
  • 122
56
votes
3 answers

Android RelativeLayout below 2 views

I have a RelativeLayout like this:
Ben
  • 16,124
  • 22
  • 77
  • 122
51
votes
1 answer

Child inside NestedScrollView not cover full height of screen

I am using NestedScrollView in my fragment. In my xml inside a RelativeLayout but it is not covering full height of screen. Below is my code -
50
votes
4 answers

Create a new TextView programmatically then display it below another TextView

String[] textArray={"one","two","asdasasdf asdf dsdaa"}; int length=textArray.length; RelativeLayout layout = new RelativeLayout(this); RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT,…
Lope Emano
  • 503
  • 1
  • 4
  • 6
50
votes
5 answers

Android: 2 relative layout divided in half screen

I tried many times to draw 2 Relative layout aligned horizontally and divided in half screen. I design the image with paint to explain a bit better what i mean. Any suggestion?
iGio90
  • 3,251
  • 7
  • 30
  • 43
50
votes
1 answer

Can't resize a RelativeLayout inside a ScrollView to fill the whole screen

I am having a weird issue that I am not sure how to fix. I have a RelativeLayout inside a ScrollView and this scrollView has it's height set to fill_parent. So does the RelativeLayout. Still, the contents are not filling the entire screen and it's…
49
votes
17 answers

How to switch from the default ConstraintLayout to RelativeLayout in Android Studio

I have the latest android Studio (2.3 beta 3) and it seems ConstraintLayout is the default when creating a project. How can I make Android Studio use the RelativeLayout as the default layout element for new projects ?