I am using objectAnimator for animating a button from bottom to top in Android. Now i am using the below code
ObjectAnimator transAnimation = ObjectAnimator.ofFloat(button,"translationY",0,440);
transAnimation.setDuration(440);
transAnimation.start();
I have also tried with sample code below. But still the problem exists
ObjectAnimator transAnimation = ObjectAnimator.ofFloat(loginLayout, "translationY",0f,0.8f);
transAnimation.setDuration(480);
transAnimation.start();
It works fine in large screen devices. But when it comes to small screen devices it goes off the screen. I want to stay it in the top of the screen irrespective of different screen sizes. I think i have to give values in percentage (say 0% to 100% or 0 to 100%p). So my question is how to give values in percentage in objectAnimator in Android. I also noticed one thing that this objectAnimator is introduced only in HoneyComb. So is there any backward compatibility libraries for running it in low versions. Could anyone guide me to find a solution for this.
I also tried extending View and writing getter and setter for the property in offset()
. Still it does not move fully to top of screen. Here is the code I have used.
@SuppressLint("NewApi") public float getXFraction()
{
int width = context.getWindowManager().getDefaultDisplay().getHeight();
return (width == 0) ? 0 : (getY());
}
@SuppressLint("NewApi") public void setXFraction(float xFraction) {
int width = context.getWindowManager().getDefaultDisplay().getWidth();
setY((width > 0) ? (width) : 0);
}
Thanks inAdvance