How to place an image and a label on a button in titanium?

Below is my code for it. It works great for iPhone, but the images are stretched for Android, so it does not show a shortcut.

var friendsButton = Titanium.UI.createButton({ top : 0, left : 91, width : 90, height : 101, style : 0, backgroundImage : '/img/buttonMiddle.png', image : '/img/friendcopy.png' }); var friendLabel = Titanium.UI.createLabel({ top : 35, left : 25, width : 100, height : 100, text : 'Friend', color : 'white', font : {fontSize:12} }); friendsButton.add(friendLabel); 

Please help me with this. I'm new to Titanium

+4
source share
2 answers

Try to install all objects (butttons / labels) in Android, for example:

 var friendLabel = Titanium.UI.createLabel({ top : '35dp', left : '25dp', width : '100dp', height : '100dp', text : 'Friend', color : 'white', font : {fontSize:'12dp'} }); 

Hope this helps.

+1
source

try to create the first view, then add to the view button, and then add images to the view, so that you achieve what you want.

 var buttonview = Ti.UI.createView(); buttonview.width = '50pt'; buttonview.height = '50pt'; var button = Ti.UI.createButton(); button.width = Ti.UI.FILL; button.height = Ti.UI.FILL; button.title = 'Activity'; button.verticalAlign = Ti.UI.TEXT_VERTICAL_ALIGNMENT_BOTTOM; button.font = { fontSize: '5pt', fontWeight : 'bold', }; buttonview.add(button); var imageview = Ti.UI.createImageView(); imageview.image = '/activities.png'; imageview.height = '80%'; imageview.width = '80%'; imageview.top = '1pt'; buttonview.add(imageview); 
0
source

All Articles