Background image under tab group

You must Login before you can answer or comment on any questions.

Hi, I have a question, I don't know if is a stupid question but I don't find a solution.

I created a window with a background image (320 x 480) and I added a tab group.

The tab group don't stay in front the background of the window but the background height is deformed.

I've tried to set z-index to window (0) and tab group (100) but doesn't work.

How I can maintain the background at 100% of height? Thank you

Application type: mobile Platform & version: iOS Device: iOS simulator, Host Operating System: OSX

2 Answers

Accepted Answer

Hi Luca

If you could provide an example of your code (simplified if possible) to demonstrate what you mean, that way people can run the code, see the issue and report back to you.

I am not sure if you are saying you have created BOTH a window containing a background image AND a tab group which would also contain at least one window per tab. If this is the case then be aware that the Tab group should be added to the context first and windows that are not part of the tab group should be opened over the top of the tab group.

However your background image problem is actually a simple one - once explained. When you add a background image to a window the space it has available to display in is determined by the internally available space. In the case of an app with the top status bar, title/nav bar and tab bar the remaining space is 320x367. As the background image so the image will be shrunk to fit. The same thing will occur if you add an image view to the window.

You can however add a standard view to the window and then add an image view to this standard view, that way the image maintains its size and will (in this example) position itself to the top of the available space and the remainder will be clipped below. You could of course adjust the top parameter entry to a negative -64 which will visually place the background image at the top of the phone.

var viewBack = Ti.UI.createView({
    height: Ti.UI.SIZE,
    top: 0,
    width: Ti.UI.SIZE
});
win.add(viewBack);
var imgBack = Ti.UI.createImageView({
    image: 'background.png',
    height: 480,
    top: 0,
    width: 320
});
viewBack.add(imgBack);

Thank you very much for your help, it's working with your code!

But if I set height:480 and width:320 (resolution iPhone 3) then i use @2 for iPhone 4 images, how width and height values changes? It's work automatically or i must use a condition?

Thank you

— answered 10 months ago by Luca Proserpio
answer permalink
1 Comment
  • You're welcome.

    No need to change the image width or height values to accommodate the retina version - it happens automatically.

    When working on the iPhone 320 is the width for both the standard resolution and the retina resolution. The reason for this is that by entering only a numeric value it is interpreted as density-independent pixels and not physical pixels.

    This can be better understood in the documentation for the 2.0 layout changes (things are so much easier now) Titanium 2.0 Layout Changes and scrolling down to Universal Unit Support.

    Here you will see that a width 320 or '320dip' means from far left to far right of standard or retina iPhones. Whilst '320px' would go from far left to far right on an standard display but from far left to halfway across on a retina.

    The reason for this is simply to make things easier to code and to allow full support of both resolutions. For most none-game apps you may never need to specify anything other than straight numbers as in 320x480 even if the device uses a retina display. Your app will take advantage of the extra pixels automatically by you providing double resolution version of ALL images and making sure to suffix the @2x before the dot extension.

    Quick examples;

    width: 320  // makes the width go from far left to far right
    width: '320dip' // exactly the same as above (note use of quotes)
    width: '320px' // full width on standard half width on retina (note use of quotes)
    width: Ti.UI.SIZE // makes the width the same size as the contents (provided other factors do not reduce this)
    I now almost exclusively use Ti.UI.SIZE as it handles the complexity automatically and means provided I design layouts that can accommodate variations in image sizes (for example) then I do not have to hard code the actual widths and heights. Makes multiple level nested layouts extremely easy.

    Only occasionally will you need to fix the width and height, as in my first answers example.

    So you get the best of both worlds, your app is built for both resolutions but you can choose to take advantage of the extra pixels when the device has them.

    — commented 10 months ago by Malcolm Hollingsworth

Your Answer

Think you can help? Login to answer this question!