Android place Relative Layout below Relative Layout programmatically

user3097511

Hi I am having troubles trying to get this Relative Layout placed below another Relative Layout. In my Activity I have a NavBar (RelativeLayout) that is aligned to the top of the activity. I would like to place my TitleBar (RelativeLayout) below this programmatically.

Here is my onCreate method where I allocate both the NavBar and TitleBar and add them to my Activity. The NavBar is correctly aligned at the top of the activity, however, the TitleBar is aligned with the top of the activity as well. I'd like the top of the TitleBar to align with the bottom of the NavBar so it is placed below the NavBar.

    super.onCreate(bundle);

    Context context = getApplicationContext();
    RelativeLayout.LayoutParams params;

    //navbar
    this.navBar = new BINavBar(context);
    relativeLayout.addView(this.navBar);

    params = (LayoutParams)this.navBar.getLayoutParams();
    params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    this.navBar.setLayoutParams(params);

    //titleBar
    this.titleBar = new BITitleBar(context);
    relativeLayout.addView(this.titleBar);

    params = (LayoutParams)this.titleBar.getLayoutParams();
    params.addRule(RelativeLayout.BELOW, R.id.BINavBar_layout);
    this.titleBar.setLayoutParams(params);
BVB

I don't think you are actually setting the id of the nav bar. Try the following:

super.onCreate(bundle);

Context context = getApplicationContext();
RelativeLayout.LayoutParams params;

//navbar
this.navBar = new BINavBar(context);
relativeLayout.addView(this.navBar);

params = (LayoutParams)this.navBar.getLayoutParams();
params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
this.navBar.setLayoutParams(params);
this.navBar.setId(R.id.BINavBar_layout); // this is the change

//titleBar
this.titleBar = new BITitleBar(context);
relativeLayout.addView(this.titleBar);

params = (LayoutParams)this.titleBar.getLayoutParams();
params.addRule(RelativeLayout.BELOW, this.navBar.getId()); // this should use navBar's id
this.titleBar.setLayoutParams(params);

Note that you may need to set the id yourself. Are you sure that R.id.BINavBar_layout exists? If not, try using the following function: View.generateViewId()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Android place Relative Layout below Relative Layout programmatically

From Dev

Place a button in Relative layout below the custom zoomview

From Dev

Android: Relative layout content goes below screen

From Dev

How to set Margin for Relative Layout programmatically in android?

From Dev

Zooming a layout (Relative Layout) in android

From Dev

Zooming a layout (Relative Layout) in android

From Dev

Relative layout: layout_below a CenterVertical element

From Dev

android relative layout design

From Dev

Infalting Relative Layout Android

From Dev

Relative layout android loopable

From Dev

Android relative layout issue

From Dev

Android Relative Layout

From Dev

Android relative layout positioning

From Dev

Android relative layout center

From Dev

Relative layout android loopable

From Dev

Android Relative Layout position

From Dev

Android: Relative Layout

From Dev

Android relative layout, right align a textview below another textview

From Dev

how to set each layout below another layout inside relative layout in android

From Dev

how to set each layout below another layout inside relative layout in android

From Dev

How to get programmatically width and height of Relative - Linear layout in android?

From Dev

Android Relative Layout with sticky footer

From Dev

Android Relative Layout image overlay

From Dev

Android Relative layout "is not a sibling" error

From Dev

Android Relative Layout Padding Issues

From Dev

Android complex layout linear and relative

From Dev

Android - Relative layout inside ScrollView

From Dev

Android Relative Layout alignParentRight and alignParentEnd

From Dev

Alignment of views in relative layout android

Related Related

HotTag

Archive