Answer the question
In order to leave comments, you need to log in
ObjectAnimator - is it possible to specify percentage values in xml?
Good afternoon, I ran into a problem when translating animation to objectAnimator, it used to be like this:
<translate
android:duration="400"
android:fromXDelta="0%p"
android:fromYDelta="0%p"
android:toXDelta="0%p"
android:toYDelta="100%p" />
<objectAnimator
android:interpolator="@android:anim/accelerate_interpolator"
android:propertyName="translationY"
android:valueType="floatType"
android:valueFrom="0.0"
android:valueTo="1000"
android:duration="400"/>
Answer the question
In order to leave comments, you need to log in
In general, ObjectAnimator eats percentage values, but for this you yourself will have to implement functions for setting and receiving values for animation. For example, you need to change the FrameLayout length from 0 to 25% of the screen size, then there will be something like this:
public class SlidingFrameLayout extends FrameLayout
{
private static final String TAG = SlidingFrameLayout.class.getName();
public SlidingFrameLayout(Context context) {
super(context);
}
public SlidingFrameLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public float getXFraction()
{
int width = getWindowManager().getDefaultDisplay().getWidth();
return (width == 0) ? 0 : getX() / (float) width;
}
public void setXFraction(float xFraction) {
int width = getWindowManager().getDefaultDisplay().getWidth();
setX((width > 0) ? (xFraction * width) : 0);
}
}
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:propertyName="xFraction"
android:valueType="floatType"
android:valueFrom="0"
android:valueTo="0.25"
android:duration="500"/>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question