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
49
votes
7 answers

ImageView fills parent's width OR height, but maintains aspect ratio

I have a square image (though this problem also applies to rectangular images). I want to display the image as large as possible, stretching them if necessary, to fill their parents, while still maintaining the aspect ratio. The image is smaller…
46
votes
4 answers

Programmatically set android:layout_centerHorizontal

In xml you can do the following: How would I, when I have the instance of TextView, do this programmatically?
nhaarman
  • 98,571
  • 55
  • 246
  • 278
44
votes
7 answers

Android Relative Layout Align Center

I am trying to create a List Activities Item Layout as follows
Harsha M V
  • 54,075
  • 125
  • 354
  • 529
43
votes
9 answers

Scale background image to wrap content of layout

I have a layout that contains some text fields and has a background image that's displayed at the top of my activity. I'd like the background image to scale to wrap the content (don't care about aspect ratio). However, the image is larger than…
43
votes
7 answers

Expand TextView with wrap_content until the neighbor view reaches the end of the parent

I need to achieve the following layout: I have two TextViews in a relative layout: the green one is fixed text with wrap_content, the black one has dynamic text with wrap_content. The black text can change and become very long. I want the black…
Y2theZ
  • 10,162
  • 38
  • 131
  • 200
43
votes
4 answers

Circular dependencies cannot exist in RelativeLayout, android?

I have the following layout: I need to keep the button at the bottom of screen and it should be visible to the user. The rest of the layout should scroll.
WISHY
  • 11,067
  • 25
  • 105
  • 197
36
votes
2 answers

Is there a way to fill parent minus a fixed number in Android RelativeLayout?

I have an ImageButton that I want to fill its parent RelativeLayout container for its width but minus a few dp so it has some left and right padding. I tried fill_parent-10dp but that causes an error and doesn't render.
34
votes
12 answers

How to put one View over other in RelativLlayout programmatically in Android?

I am programmatically creating view in Android. Parent layout is RelativLlayout and I'm adding two views in it. First is ListView and second is custom view. I want my second custom view to come on top of the list, but somehow it is getting hidden…
Chimu
  • 758
  • 1
  • 6
  • 16
32
votes
4 answers

Repeat Image in with ImageView in RelativeLayout

I want to repeat the image with ImageView with in RelativeLayout. Can it be possible to use the Bitmap xml and use tilemode "repeat" with RelativeLayout, because what I have seen things on Internet they all dealing with LinearLayout. Any help or…
Usman Kurd
  • 7,212
  • 7
  • 57
  • 86
32
votes
4 answers

Android RelativeLayout align center of one view on top right corner of another view

I have experience with RelativeLayout but I've never run across a way to solve the problem I am presented with (aside from hard coding margin values, which I want to avoid.) I want to try to create something like the following image in a…
FoamyGuy
  • 46,603
  • 18
  • 125
  • 156
31
votes
5 answers

android RelativeLayout change height programmatically

I try change layout height programmatically. I have two buttons. In one button I change my layout position and second button I try to receive save position witch I was first time.
Beka
  • 341
  • 1
  • 5
  • 10
31
votes
1 answer

What's the difference between alignBaseline and alignBottom in Android?

I tried both to align a few TextView objects and they gave me the same results. What exactly is the difference between 'baseline' and 'bottom' ?
Akshay Damle
  • 1,220
  • 3
  • 18
  • 31
30
votes
4 answers

Android: RelativeLayout in ScrollView

I have a RelativeLayout with multiple ImageViews and when I turn around the screen, the ImageViews become disordered. So I decided to wrap it into a ScrollView. But the ScrollView doesn't work! Can any one help me with that? I know that the right…
29
votes
5 answers

Android RelativeLayout alignCenter from another View

I have a RelativeLayout with two children that are also both RelativeLayouts containing a few buttons and things. These children layouts are not centered in my main layout, and the main layout does contain some other things off the the sides of…
FoamyGuy
  • 46,603
  • 18
  • 125
  • 156