Titanium: Image -> “auto”

2019-08-23 04:18发布

问题:

Let's say I have an image called hello.png with dimensions 200x100. I create a button using that hello.png like this:

var button = Titanium.UI.createButton({
bottom : 50,
backgroundImage : "images/hello.png",
width:100,
height:"auto";
});
window.add(button);

What would be the appearance of the height of the button on the device? Would it be 200 pixels or would it be much less than 200 (maybe say 50)?

Based on what I've found on google, the button should be 200 pixels. But when I compile the app, the button height is greatly shrunken :/

回答1:

If you avoid the height=auto, it will work.It will take the parent height in some case the auto height value wont be equal to the parent window height. In the below code sample it will work as the button width will be fixed to 100 but the height will be changing accordance with the window size.

var window = Titanium.UI.createWindow();
var button = Titanium.UI.createButton({
    bottom : 50,
    backgroundImage : "assets/images/boston_college.png",
    width:100
});
window.add(button);
window.open();