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
ajaysainsgvu
Posts: 242
Registered: ‎02-19-2013
My Device: 9500
Accepted Solution

How can i make this layout.

3.png

 

I need to make this layout using Horizontal Field Manager. Can anyone help me for this..

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: How can i make this layout.

hfm with use_all_width, red background.
labelfield with paddings appropriately set, and overwritten paint method to change the font color to white.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: How can i make this layout.

I think you can do this with just a LabelField too.  On constructor use style USE_ALL_WIDTH, set the background - setBackground() - and padding - setPadding() - and font - setFont() - and override paint() to set white text color as per Simon's suggestion. 

Developer
ajaysainsgvu
Posts: 242
Registered: ‎02-19-2013
My Device: 9500

Re: How can i make this layout.

This red color is background image. So I do not want to use background color method. Instead of this I have to  use the red image. Then How can i make.

Developer
ajaysainsgvu
Posts: 242
Registered: ‎02-19-2013
My Device: 9500

Re: How can i make this layout.

I am doing like this but label is not displaying why its so?

 

HorizontalFieldManager hfm = new HorizontalFieldManager(Field.FIELD_LEFT | Field.USE_ALL_WIDTH) {
            protected void paint(Graphics graphics) {
                Bitmap background = Bitmap.getBitmapResource("img/top-bar.png");
                graphics.drawBitmap(0, 0, background.getWidth(), background.getHeight(), background, 0, 0);
                super.paintBackground(graphics);
            }
        };
        LabelField lb1 = new LabelField(GlobelVars._resource.getString(Home_Title), Field.FIELD_HCENTER) {
            protected void layout(int width, int height) {
                super.layout(width, height);
                setExtent(100, 30);
            }
        };
        hfm.add(lb1);

Developer
ajaysainsgvu
Posts: 242
Registered: ‎02-19-2013
My Device: 9500

Re: How can i make this layout.

How can I set the padding of text in labelfield.??
Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: How can i make this layout.

"This red color is background image"

 

Perhaps next time you would explain any additional requirement like this at the start?

 

If you investigate, you will see that the BackgroundFactory has methods for creating a background from a Bitmap and tiling the image if you need to.  Then you can use setBackground(). 

 

"I am doing like this but label is not displaying why its so?"

 

You code looks nothing like what Simon or I suggested.  We never suggested overriding layout, and the only paint method we suggested overriding was for LabelField.  I suggest you review what we suggested and try again. 

 

"How can I set the padding of text in labelfield.??"

The setPadding() method is not documented until later OS, but exists and works in OS's after 4.2.  So use the setPadding() method.

 

Some comments about your code:

 

Bitmap background = Bitmap.getBitmapResource("img/top-bar.png");

Don't do things in your paint method that you don't have to, remember that paint gets called frequently and you are asking it to load a Bitmap and convert it to graphics form for every paint!  If you do this for other Fields, you will impact your apps performance and drain the battery quicker. 

 

                super.layout(width, height);
                setExtent(100, 30);

 

If you ask a Field to layout itself out, then stick to the extents that it requires.  If you want to do something else, be very careful, you are likely to confuse the Field when it comes to paint and discovers the area is supposed to paint into is nothing like the area it actually asked for. 

 

Anyway try again doing what Simon and I suggested, and you should get what you want. 

 

There are