Search code examples
titaniumappcelerator-mobile

How i set TextField height property according to Size wise in Appcelerator Allow?


I am new developer with Appcelerator Alloy. Plz help me, how i set Textfield Height Property according to device Display Size.

in Titanium.

  var name_Txt = Titanium.UI.createTextField({
        height : (Ti.Platform.displayCaps.platformHeight< 481) ? 32 : Ti.Platform.displayCaps.platformHeight * 6 / 100,
        width : "94%",
        backgroundImage : "../images/textfield_dropdown.png",
        top : "10",
        paddingLeft : "10",
        hintText : "Input Activity - optional scroll",
        font : {
            16,
            fontWeight : "bold",
        },
    });

in Alloy

<TextField height="?" id="name_Txt" left ="2%" paddingLeft = "5" backgroundImage = "/appimage/textfield.png" width ="60%"></TextField>

or in .tss file

"#name_Txt":{
height : ?,
}

Thanks in advance,


Solution

  • Just do it programmatically in the controller file for this view. For example,

    Say you have a view named main.xml

    <Alloy>
        <TextField id="name_Txt"></TextField>
    </Alloy>
    

    A style file named main.tss:

    "#name_Txt":{
        left : "2%"
        paddingLeft: 5,
        backgroundImage: "/appimage/textfield.png",
        width:"60%"  
    }
    

    And a controller named main.js:

    $.name_Txt.height = (Ti.Platform.displayCaps.platformHeight< 481) ? 32 : Ti.Platform.displayCaps.platformHeight * 6 / 100;