I have an imageView inside of a scrollView that I want to be able to move based on the accelerometer. Below is the relevent code:
var scrollView = Titanium.UI.createScrollView({ top:125, contentWidth:480, contentHeight:480, zIndex:4, height:260, width:300 }); var imageView = Titanium.UI.createImageView({ images:images, zIndex:5, duration:50, repeatCount:0 }); scrollView.add(imageView); Titanium.Accelerometer.addEventListener('update',function(e) { imageView.animate({center:{x:imageView.center.x += (e.x * 10),y: imageView.center.y -= (e.y * 10)},duration:1}); });Now, the imageView shows up fine in the Simulator, but when I push the app to the device using Titanium, the imageView doesn't show up.
Anyone have an idea what is going on here, and is this the best way to animate the imageView using the accelerometer?
7 Answers
Good Question, I have a similar situation. No thoughts from those in the know?
I don't know if this is relevant but a coworker encountered a similar issue with native Objective-C code. They had a PNG image properly showing up in the simulator but not displayed with the device. The image was there (responding to events) but still invisible.
It appeared to be a problem with the image path (a space or a special character). You may want to check your path if you still have this problem.
I've had the same problem, with images showing up when using the simulator, but not on the device. Your problem may be different, but as I've found this question while searching for my problem, I'm posting here, hoping it'll help someone.
My problem was that the images were saved from an XHR request. I was using:
var f = Titanium.Filesystem.getFile('test.jpg'); f.write(this.responseData);The problem seemed to be the getFile method, the first parameter should be the directory path:
var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'test.jpg');
This worked for me!
var thumb = Ti.App.Properties.getString('theImage'); var file = Ti.Filesystem.getFile(thumb); var image = file.read(image); var thumbnailView = Titanium.UI.createImageView({ image:image, height:150, width:150 }); view.add(thumbnailView);
I am having a similar problem with text animation
Had this issue also yesterday. With android run: adb -e logcat
And you should be able to see what the problem is. For me it was Titanium not copying across content & folders to the emulator. In some situations running touch * in the folders on the desktop was enough to get titanium to copy it over. The other issue was more painful - essentially titanium applying some weird rules to paths. This was fixed by using the latest nightly build for Android from http://drop.io/titanium_android_nightly and then using paths ala:
Titanium.UI.createWindow({url:"code/dashboard.js",backgroundImage:'app://images/dashboard.png',navBarHidden:true,fullscreen:true});
I had this same problem and was happy to see that the solution was a simple one in my case. I had placed my files in a folder called 'Images' with an uppercase 'I' in my project folder but had referenced it as 'images' with a lowercase 'i' in my code. As soon as I changed the folder name to 'images' with the lowercase 'i' everything worked fine.
Your Answer
Think you can help? Login to answer this question!