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
29
votes
1 answer

PercentRelativeLayout, how to set the height programmatically

I am using PercentRelativeLayout from android percent support package. this is what I have in my layout.
g.revolution
  • 11,962
  • 23
  • 81
  • 107
28
votes
2 answers

How do I set background image with picasso in code

I know picasso loads image into imageview etc but how do I set my layout background image using picasso? My code: public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { …
Toye
  • 483
  • 1
  • 4
  • 7
27
votes
5 answers

match_parent property for children in a RelativeLayout

In short, is it possible to tell a child in a RelativeLayout to always match the height of that RelativeLayout regardless of how other children in that same RelativeLayout behave? In short, that's it. Details below. What I'm trying to achieve is a…
davidcesarino
  • 16,160
  • 16
  • 68
  • 109
25
votes
1 answer

Android relative layout align parent right

I have following layout:
Damir
  • 1,092
  • 4
  • 18
  • 32
25
votes
3 answers

Is there a way to offset a view from center?

I'm trying to possition my button not exactly in center, but let's say in the 2/5s of the screen height, I was looking for attribute unsuccessfully, so I tried this approach
urSus
  • 12,492
  • 12
  • 69
  • 89
24
votes
2 answers

Extending RelativeLayout, and overriding dispatchDraw() to create a zoomable ViewGroup

I've seen a few people ask how to zoom an entire ViewGroup (such as a RelativeLayout) in one go. At the moment this is something I need to achieve. The most obvious approach, to me, would be to hold the zoom scale factor as a single variable…
Trevor
  • 10,903
  • 5
  • 61
  • 84
24
votes
4 answers

how to put a border around an android relativelayout?

I've seen this subject about puting a border around an android textview, and I used it. But now, I would like to put a border around widgets which are situated into a relative layout. How can I do it?
AyaAndro
  • 241
  • 1
  • 2
  • 3
23
votes
2 answers

Android: Align Parent Bottom + Bottom margin programmatically

How can I programatically add a RelativeLayout that is aligned to the bottom of parent, and add a margin or padding in the same RelativeLayout? Example:
Igor Ronner
  • 1,565
  • 2
  • 14
  • 31
23
votes
4 answers

How to make image fill RelativeLayout background without stretching

In my Android project, I am not quite sure how to make my background image fill the entirety of the RelativeLayout root element in XML, which is the size of the screen. I want to be sure that this works for all aspect ratios, so the image will clip…
pqn
  • 1,522
  • 3
  • 22
  • 33
22
votes
2 answers

Custom view's onMeasure: how to get width based on height

The previous version of my question was too wordy. People couldn't understand it, so the following is a complete rewrite. See the edit history if you are interested in the old version. A RelativeLayout parent sends MeasureSpecs to its child view's…
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
22
votes
6 answers

accepting click events in RelativeLayout

I have a RelativeLayout with a few TextView as children
skooter
  • 286
  • 1
  • 2
  • 11
21
votes
7 answers

RelativeLayout "Couldn't resolve resource..." Android

When using the below code, I get an error "Couldn't resolve resource @id/item1" Why is this? id/item1 is added before I use it, so I'm not sure why this is coming up.
kieblera5
  • 577
  • 2
  • 5
  • 7
21
votes
4 answers

Using layout_above in a RelativeLayout

Can someone explain to me why the ImageView is not appearing above the LinearLayout?
Andrew
  • 20,756
  • 32
  • 99
  • 177
21
votes
2 answers

RelativeLayout height to fill remaining space

I have the following layout in my xml file:
Alin
  • 14,809
  • 40
  • 129
  • 218
21
votes
7 answers

RelativeLayout: align View centered horizontal or vertical relative to other view

Is it possible to align a view in XML in a RelativeLayout centered horizontal or vertical according another already existing view. For example: lets say there is something like this: The second text view should be displayed centered below the first…
sockeqwe
  • 15,574
  • 24
  • 88
  • 144