Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Super Contributor
pg1181
Posts: 398
Registered: ‎01-12-2011
My Device: Q10
Accepted Solution

How to left justify or right justify a control inside a container.

Hi,

 

I'm trying to place a label in a container to the complete left, and then another control (ToggleButton in my immediate case) on the complete right. How can I do this?

 

I've tried the following to no avail:

 

ToggleButton *toggle = new ToggleButton();

toggle->setHorizontalAlignment(HorizontalAlignment::Right);

myContainer->add(toggle);

 

Thanks!

Retired
robbieDubya
Posts: 418
Registered: ‎07-18-2012
My Device: Q10

Re: How to left justify or right justify a control inside a container.

Hi, I find trying to figure stuff like this out is done best by setting the background colour of the container holding a control... That way you can see if you're inside a container that isn't the full width (for example)... Can you provide more code, what's the parent look like?
--
Rob is no longer associated with BlackBerry.
Super Contributor
pg1181
Posts: 398
Registered: ‎01-12-2011
My Device: Q10

Re: How to left justify or right justify a control inside a container.

I've actually gotten this to work by using the following code, I'm using a DockLayout in this case:

 

//Setup controls

 

ScrollView *scrollView = new ScrollView();

scrollView->setHorizontalAlignment(HorizontalAlignment::Fill);

ScrollViewProperties* scrollViewProp = scrollView->scrollViewProperties();

scrollViewProp->setScrollMode(ScrollMode::Vertical);

 

Container *mainContainer = Container::create().left(0).right(0);

mainContainer->setHorizontalAlignment(HorizontalAlignment::Fill);

 

Container *subContainer= Container::create().left(20).right(20).top(20).bottom(20);

subContainer->setHorizontalAlignment(HorizontalAlignment::Fill);

subContainer->setBackground(Color::fromARGB(0xffffffff));

 

Container *subContainerLeft= Container::create().left(0).right(0);

subContainerLeft->setHorizontalAlignment(HorizontalAlignment::Left);

subContainerLeft->setVerticalAlignment(VerticalAlignment::Center);

 

Container *subContainerRight= Container::create().left(0).right(0);

subContainerRight->setHorizontalAlignment(HorizontalAlignment::Right);

subContainerRight->setVerticalAlignment(VerticalAlignment::Center);

 

DockLayout* subContainerLayout = newDockLayout;

subContainer->setLayout(subContainerLayout);

 

//Controls are added to left and right here!

 

subContainer->add(subContainerLeft);

subContainer->add(subContainerRight);

 

mainContainer->add(subContainer);

 

scrollView->setContent(mainContainer);

 

this->setContent(scrollView);

 

Thanks for your reply!

Retired
robbieDubya
Posts: 418
Registered: ‎07-18-2012
My Device: Q10

Re: How to left justify or right justify a control inside a container.

cool!

--
Rob is no longer associated with BlackBerry.