is it possible to fit view height to its content? When I set view height to 'auto' it takes 100% of window height
Thanks
4 Answers
var win = Titanium.UI.currentWindow; var bg = Titanium.UI.createImageView({ image: 'images/infos-bg.png', align: 'center', top: 0, width : '100%' }); var accroche = Titanium.UI.createImageView({ image: 'images/accroche.png', align: 'center', top: '35%', width : '75%' }); var h = bg.toImage().height*0.7; var sView = Titanium.UI.createView({ width:'100%', top:-h, zIndex : 999, width:'100%', height: Ti.UI.SIZE, layout:'vertical' }); var t = 0; sView.addEventListener('swipe', function(){ if(t==0){ var anim1 = Ti.UI.createAnimation({ top: 0, duration: 500 }); t=1; }else{ var anim1 = Ti.UI.createAnimation({ top: -h, duration: 500 }); t=0; } sView.animate(anim1); }); sView.add(bg); sView.add(accroche); win.add(sView);
HI Mohamed
Set your height as this example;
height: Ti.UI.SIZEThat will make the height of the view match the height of the contents.
And;
height: Ti.UI.FILLWill make the view fill to its parent height.
As long as you are using sdk 2.0 or higher - this works a charm.
It doesn't work for me :s
Hi Mohamed
I have tried your code at the properties you are using seem to conflict with one another.
You have a 'parent' view called sView which has the layout property set to vertical. You then add two image views, bg and accroche to this view.
As you have set 'vertical' as the parent views layout, the two extra views will side one underneath the other.
But you have added a top parameters to one that uses a percentage value of the parent view, however the parent view determines its size based on its parent height.
You then add an animation to the swipe event move the parent view. You are also determining the height of the imageview bg for this animation.
I will be honest and say I am not sure what you are trying to achieve from this code.
Can you provide a description of what you want it to do, and then maybe I can help further.
Your Answer
Think you can help? Login to answer this question!