Thursday, January 23, 2014

 TranslateAnimation Parameter Unit


            
I made an animation effects, floating some distance up the picture. Picture settings attributes:
marginTop = "300dp"

This picture is the distance from the top of 300dp.
After pictures floating up through TranslateAnimation animation 300dp. However, different from the floating device is different.
TranslateAnimation ani = new TranslateAnimation (0, 0, 0, -300);
I should have passed what type of argument? In 300dp based units, convert px, converted into sp. Have tried. Will not work, floating not fixed in different devices.


These generations do is open the program, so that UI interface pictures floating upward, and positioning.
Reply:
marginTop = "@ dimen / margin_top_height"

dimens.xml defined:
300dip

float yOffset = getResources () getDimension (R.dimen.margin_top_height);.
TranslateAnimation ani = new TranslateAnimation (0, 0, 0,-yOffset);

Reply:
cited a floor ncepu307 reply:
marginTop = "@ dimen / margin_top_height"

dimens.xml defined:
300dip

float yOffset = getResources () getDimension (R.dimen.margin_top_height);.
TranslateAnimation ani = new TranslateAnimation (0, 0, 0,-yOffset);

The same, although marginTOP is 300dip, but the value of such a move would still get more than the parent container.


I want to make pictures move, and then given to the movement. Did not know there are other ways?
Set ani.setFillAfter (true); Although you can locate, but other space and then bind other ani, ani this picture will continue to play ......
Reply:
cited a floor ncepu307 reply:
marginTop = "@ dimen / margin_top_height"

dimens.xml defined:
300dip

float yOffset = getResources () getDimension (R.dimen.margin_top_height);.
TranslateAnimation ani = new TranslateAnimation (0, 0, 0,-yOffset);

Sorry, I was thinking wrong ~ ani.setFillAfter (true); may solve the problem.

No comments:

Post a Comment