Answer the question
In order to leave comments, you need to log in
How to make the animation speed the same on different Android devices?
Hello.
Can you please tell me how to make the animation the same on different Android devices?
I have a TextView in the form of a circle, which should be smoothly increased to a certain size in 0.7 seconds.
I do it like this:
layout:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/oval_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/shape_oval_background" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#B6CFF5"/>
</shape>
View ovalBackground = findViewById(R.id.oval_background);
ValueAnimator animator = ValueAnimator.ofFloat(0, 230);
animator.setDuration(700);
AnimatorUpdateListener animatorUpdateListener = new AnimatorUpdateListener(this);
animator.addUpdateListener(animatorUpdateListener);
public class AnimatorUpdateListener implements ValueAnimator.AnimatorUpdateListener {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
float animateValue = (float) valueAnimator.getAnimatedValue();
final float scale = getResources().getDisplayMetrics().density;
int widthPixels = (int)animateValue * scale + 0.5f);
int heightPixels = (int)animateValue * scale + 0.5f);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(widthPixels, heightPixels);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
ovalBackground.setLayoutParams(layoutParams);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question