10

Im trying to figure out how to align a view in relative layout to its top right corner. Currently it is aligned in top left corner.

A simple problem, yet I dont know how to do it.

Here is the code:

        RelativeLayout.LayoutParams gpsViewLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT );
    gpsViewLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    gpsViewLayoutParams.addRule(RelativeLayout.ALIGN_RIGHT);
    this.relativeLayout.addView(gpsView,gpsViewLayoutParams); 
no9
  • 6,424
  • 25
  • 76
  • 115

2 Answers2

13

Use this:

gpsViewLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

instead of

gpsViewLayoutParams.addRule(RelativeLayout.ALIGN_RIGHT); 

You may get in this way.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Abhi
  • 8,935
  • 7
  • 37
  • 60
5

It is ALIGN_PARENT_RIGHT instead of ALIGN_RIGHT

http://developer.android.com/reference/android/widget/RelativeLayout.html#ALIGN_PARENT_RIGHT

rf43
  • 4,385
  • 3
  • 23
  • 28