Search code examples
titaniumtitanium-mobiletitanium-alloy

View TSS in titanium


Hi am new to titanium and cant get how to create a fluid design with its TSS. How to place three views, one as header(20%), two as content holder(60%) and three as footer(20%) with all width full(Ti.UI.FILL). My code is,

index.xml

<Alloy>
   <Window class="container">
       <Require src="home" id="home"></Require>
   </Window>
</Alloy>

home.xml

<Alloy>
    <View id="header"></View>
    <View id="content"></View>
    <View id="footer"></View>
</Alloy>

home.tss

"#home": {
    layout: 'vertical',
    width: Ti.UI.FILL,
    height: Ti.UI.FILL,
    backgroundColor: '#000'
},
'#header':{
    layout: 'horizontal',
    height: '20%',
    width: Ti.UI.FILL,
    backgroundColor: '#fff'
},
'#content': {
    layout: 'vertical',
    height: '60%',
    width: Ti.UI.FILL,
    backgroundColor: '#ccc'
},
'#footer': {
    layout: 'horizontal',
    height: '20%',
    width: Ti.UI.FILL,
    backgroundColor: '#fff'
}

What am trying is to place a back button(left), title(middle) and a refresh button(right) as horizontal layout in header view and app content in content view and in footer view with some choice with scrolling(ie, we can scroll using slide event by placing options on it). If I run this code views are eventually divided as like this and 60% not affected on the content view. I have asked in appcelerator forum and dint get replied yet. Hope this helps.


Solution

  • Your object with the id of 'home' isn't actually a view, it's just a reference to the home class and so you can't attribute styles to it like that.

    I would have relaid home.xml out like this:

    <Alloy>
        <View id="homeHolder">
            <View id="header"></View>
            <View id="content"></View>
            <View id="footer"></View>
        </View>
    </Alloy>
    

    and then this would have work as you would have expected

    "#homeHolder": {
        layout: 'vertical',
        width: Ti.UI.FILL,
        height: Ti.UI.FILL,
        backgroundColor: '#000'
    }