Animating an element in 'dp'

You must Login before you can answer or comment on any questions.

Is it possible to assign a value in android's 'dp' units to the UI.animate? Whenever I try I get an error that reads: "unable to parse '126dp' as an integer."

But if I run parseInt on the variable before passing it to UI.animate then the 'dp' is stripped from the value when it arrives at UI.animate.

I'm trying to get some views to slide left a consistent amount regardless of screen resolution. Currently, the animation moves the correct distance on a 240x320 screen at ~130 dpi but not at ~150dpi. There

Ti.App.addEventListener('Next',function(data){
        var rtop = '5dp', 
            newleft = (ribvw.left-64)+'dp';  /*ribvw.left is the left edge of the view that should animate left */
        ribvw.animate({left:newleft,top:parseInt(rtop),duration:500},function(){
            ribvw.left=newleft;
        });
    });

2 Answers

Accepted Answer

Check out this post as I had the same issue. http://developer.appcelerator.com/question/134915/animate-function-does-not-accept-dp-values

You can pull the function convertToPixel from the code. Basically you pass in the dp value and it will return the pixel value for the animate function.

Since SDK 2.x the numbers defaults to dip so when you leave out the suffix dp it should be converted to Dip. I am not quite sure if this applies to the animation also. Good luck :)

Your Answer

Think you can help? Login to answer this question!