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

Java Development

Reply
Developer
Posts: 130
Registered: ‎10-26-2010
My Device: Blackberry Bold 9700
Accepted Solution

button not align to right on all resolutions

hi All ,

 

am showing my app logo and a  button at the top of the screen. Every thing is just OK but only problm is with the button which has to b align to right at a specifc positiion from right side

The problm I am facing is that when I place the  button on the required position its not on the same place on all handsets

Here is my code

	public  HorizontalFieldManager getField(){

		HorizontalFieldManager hfmc = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH| 
				HorizontalFieldManager.USE_ALL_HEIGHT)
		{	
		
			protected void paint(Graphics graphics) {
				int xForLogoImg = (Display.getWidth()*4)/100;
				graphics.drawBitmap(0, 0, imgTitleBar.getWidth(),imgTitleBar.getHeight()+5, imgTitleBar, 0, 0);
				graphics.drawBitmap(xForLogoImg, 0, imgTitle.getWidth(), imgTitle.getHeight()+5, imgTitle, 0, 0);
				super.paint(graphics);
			}	
		};	

		
		int left = Display.getWidth() /2 +  ((Display.getWidth()*6)/100) ;
		
		btn.setMargin(0, 0, 0, left);
		hfmc.add(btn);
		return hfmc;
	}

 

  I return an HFM on which my logo is drawn and button is added . I have set the left margin of the button to the extend I want to b

Its OK on 9800 resolution 360X480 but on 9780 (resoltuion 480x360) its more toward the left and as resolution inc  button move more to left

 

thnx in advnc to all of u

 

Regards

Developer
Posts: 40
Registered: ‎09-08-2011
My Device: 8900
My Carrier: AIS

Re: button not align to right on all resolutions

Should be e.g.:

 

int left = Display.getWidth() - 100;
Rather than "go to the middle, then a bit more" Smiley Wink
Developer
Posts: 130
Registered: ‎10-26-2010
My Device: Blackberry Bold 9700

Re: button not align to right on all resolutions

 thnx for ur reply @pbrebs

 

if  do as u said than button looks OK on 9800 (resolution 360x480)  but on resolution 480x360 and 640x420  button move more to the right even its label is shorten to adjust  it thr

 

I need a genralized way so that button adjust itself with respect to resolution

 

Regards

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: button not align to right on all resolutions

Have you looked at the Style Field.FIELD_RIGHT?

 

This works in places and doesn't in other places, it all depends on the Manager.  One place here I am confident it does not work is in HorizontalFieldManagers.  But I think it does work OK in VerticalFieldManagers where the VFM has USE_ALL_WIDTH.  So try adding your button to a VFM instead of a HFM, with Field,FIELD_RIGHT. 

 

Aside from that, you are up for creating a customer Manager.  This Manager will call the layout on the Button, then ask it how big it is, and use the Manager's width to determine the position to set this Fields Position.  All pretty standard Manager stuff though fairly daunting to a Manager newbie.

 

You will find more on this in the following:

http://supportforums.blackberry.com/t5/Java-Development/Create-a-custom-layout-manager-for-a-screen/...

and

http://supportforums.blackberry.com/t5/Java-Development/How-to-Extend-Manager/ta-p/446749

Developer
Posts: 130
Registered: ‎10-26-2010
My Device: Blackberry Bold 9700

Re: button not align to right on all resolutions

[ Edited ]

Thnx @peter it helped .

 

 But I dont understand I am placing two images using this same percentage method and its working fine and images are palced on right place with respect to resolutions

 

Why it did not worked for the button ?

 

Regards

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: button not align to right on all resolutions

Rim Fields are not consistent in the way they behave.

 

For example LabelField will only ask for the width it needs, BasicEditField will ask for all the width.  BitmapFields will ask for the width they need, Buttons do different things depending on the level of OS.  All very confusing.