Reputation: 565
I am trying to use ObjectAnimator for slide up translate animation because, as we know onclicklistener won't work if we use normal translation animation like this,
<translate
android:duration="1000"
android:fromYDelta="100%"
android:toYDelta="10%" />
The above xml code works fine but as I said before onclicklistener not working after animation. I tried ObjectAnimator like the below one
ObjectAnimator mover = ObjectAnimator.ofFloat(filterLayout, "translationY", 1.0f, 0.1f);
mover.start();
But it doesn't give the same result as translate xml does.
Any help would be appreciated.
Upvotes: 4
Views: 3919
Reputation: 2126
I know it's late but, please check the below code and see if works for your case. I took the XML code you shared as a reference to this.
ObjectAnimator.ofPropertyValuesHolder(
view,
PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, 100.0f, 10.0f));
Upvotes: 2
Reputation: 923
Your problem here is that the values that you pass to ObjectAnimator are not percentage, but absolute values.
So you have to calculate the view's height and then pass it to the ObjectAnimator ie .
ObjectAnimator.ofFloat(filterLayout,"translationY",calcHeight,calcHeight * 0.1f);
Upvotes: 2