简体   繁体   中英

set layout_below of RelativeLayout within a Relative Layout programmatically

I have a RelativeLayout @+id/main_layout .
Inside the @+id/main_layout , I have a TextView @+id/txt1 and a RelativeLayout @+id/store .
For some reason I have to set android:layout_below="@+id/txt1" to the inner RelativeLayout @+id/store programmatically. How to do that?

Can you try adding it like this:

RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
relativeParams.addRule(RelativeLayout.BELOW, idOfTheViewBelow);

Of course, use parameters (fill parent etc.) which you need!

Edit: Of course, you don't need to create the RelativeLayout , just instantiate your own, and apply the rules you need!

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