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

Accessing attrs in AttributeSet for custom components

I've got a custom component containing two TextViews that have a custom size-setting method on (the two text views are proportional by about a 1:2 ratio). Being that this is a subclass of RelativeLayout, it doesn't have a textSize attribute, but I'm…
Josh Kovach
  • 7,679
  • 3
  • 45
  • 62
20
votes
3 answers

How to put RelativeLayout inside CoordinatorLayout

I'm trying to recreate the search box as it is in Airbnb Android app. So I'm using CoorinatorLayout with Toolbar and RecyclerView. But when I insert something inside the Coordinator besides those two things, it doesn't show up. Here is my…
20
votes
5 answers

z-index in Relative layout

I need to place a TextView above the Button in RelativeLayout. But it is not working: TextView is always under the Button, even if I move it before the button. I also tried bringChildToFront() function to move textview on front, but no…
Evgeny Borzenkov
  • 1,107
  • 3
  • 12
  • 19
19
votes
7 answers

Unexpected namespace prefix "app" found for tag RelativeLayout - Android?

I need to use BottomSheetBehavior with ScrollView but it says to me : Unexpected namespace prefix "app" found for tag RelativeLayout app:behavior_hideable="true" app:behavior_peekHeight="80dp" Here is my xml :
user4813855
19
votes
1 answer

RelativeLayout align parent *side* + margin *side*

I've noticed a strange behavior in RelativeLayout when you align a view to the layout's side (any side) and having a large margin in the same direction. I have 2 RelativeLayouts that each contains a simple view. In one layout that view is align to…
19
votes
8 answers

How to center a view using RelativeLayout?

I wanted to know how to center a View between two other views (or between a view and the parent edge) using RelativeLayout. For example, if I have the following... How do I vertically center the Button between the ImageView and the bottom of the…
Gus
  • 2,531
  • 4
  • 22
  • 28
18
votes
1 answer

How to put AdView in ConstraintLayout at bottom and below other stuff?

I'm trying to migrate from RelativeLayout to ConstraintLayout but I'm having problems adding the AdMob AdView to the bottom and the rest of the content above it. For example, using RelativeLayout was that simple. You only need to put…
17
votes
3 answers

Programmatically adding items to a relative layout

I have been searching everywhere for an answer to this question. I'm new to Android and attempting to add items to a relative layout programmatically through java instead of xml. I have created a test class to try it out but the items keep…
user597436
  • 173
  • 1
  • 1
  • 4
17
votes
4 answers

Android ScrollView fillViewport not working

I have a simple layout with a name on the top, and a button which I want to be at the bottom of the screen, or beyond that in case I add more items. So I am using a ScrollView with a LinearLayout as follows:
17
votes
2 answers

Why do I get white space on top and on the bottom of my ImageView in my RelativeLayout?

I am using a relativelayout to overlay to images. On all screen sizes so far that I have tested (from 2.7 to 10.1 inch) I always get white space on top of my image. In my IDE I always see that my relativelayout is causing the extra space on top and…
user2426316
  • 7,131
  • 20
  • 52
  • 83
17
votes
6 answers

Android GLSurfaceView transparent background without setZOrderonTop

Sorry for my English. My work is based on https://github.com/harism/android_page_curl/ After many hours of research, I have found a few solutions, but not for all the issues what I have in my application. I've some trouble with a GLSurfaceView. I've…
CharlesD
  • 247
  • 1
  • 3
  • 5
17
votes
5 answers

Android arrange layout with height as percentage

I am very new to android and practicing. I am trying to design a screen. which will contain a background image and a floating container with sliding menus. ( For more details please find the attached image ) My layout consists of a background image,…
ramesh
  • 4,008
  • 13
  • 72
  • 117
17
votes
2 answers

Programmatically set attribute AlignParentRight to button in RelativeLayout is not working?

I try to programmatically set the attribute AlignParentRight to button in RelativeLayout but the program crashes with a NullPointerException. Here my code: //add horizontal realative layout RelativeLayout layouth = new…
Mokkapps
  • 2,028
  • 9
  • 42
  • 67
17
votes
3 answers

FrameLayout to RelativeLayout ClassCastException even if there is no FrameLayout used

In my application, I have a layout which has a RelativeLayout to which I want to set margins at runtime programmatically. But when I do that, it gives me ClassCastException saying FrameLayout can not cast to RelativeLayout. I don't have any…
17
votes
6 answers

RelativeLayout add rule "RelativeLayout.LEFT_OF" not working

I have a relativeLayout like below:
dreamtale
  • 2,905
  • 1
  • 26
  • 38