简体   繁体   中英

How do i align a view in RelativeLayout to top-right corner

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); 

Use this:

gpsViewLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

instead of

gpsViewLayoutParams.addRule(RelativeLayout.ALIGN_RIGHT); 

You may get in this way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM