Как создать многоимпульсную анимацию из изображения - PullRequest
0 голосов
/ 22 мая 2019

[ссылка на изображение] https://media.giphy.com/media/LSRm7w1EKbrFxlFS3m/giphy.gif Я создал образец с импульсной анимацией. Это работает, как и ожидалось, но мне нужна помощь в создании нескольких импульсов. Ниже приведен код, который я использовал. Ваша помощь очень ценится.

Как показано на рисунке, я хочу генерировать несколько импульсов при расширении кольца.

файл анимации: pulse.xml

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="2000"
        android:fromXScale="1"
        android:fromYScale="1"
        android:pivotX="50%"
        android:pivotY="50%"
        android:repeatCount="200"
        android:repeatMode="reverse"
        android:toXScale="1.1"
        android:toYScale="1.1"
        />
</set>

activity.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    tools:context=".MainActivity">
    <ProgressBar
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        style="?android:attr/progressBarStyleHorizontal"
        android:id="@+id/progressbar"
        android:text="2569**"
        android:layout_gravity="center"
        android:layout_margin="10dp"
        android:max="100"
        android:progress="100"
        android:progressDrawable="@drawable/circular_progress_bar"
        android:layout_centerInParent="true"
        />
    <TextView
        android:id="@+id/textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:gravity="center"
        android:text="2678**"
        tools:text="asdasdasdas"
        android:background="#07000000"
        android:textColor="#000000"
        android:textSize="20sp" />
</RelativeLayout>

Mainactivity.java:

val pulse = AnimationUtils.loadAnimation(this, R.anim.pulse)
        val textview = findViewById<View>(R.id.textview) as TextView
        val progressBar = findViewById<View>(R.id.progressbar) as ProgressBar progressBar.startAnimation(pulse)

1 Ответ

0 голосов
/ 22 мая 2019

попробуйте это:

bounce.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <scale
        android:duration="1000"
        android:fromXScale="0.8"
        android:toXScale="1"
        android:fromYScale="0.8"
        android:toYScale="1"
        android:pivotX="50%"
        android:pivotY="50%" />
</set>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    tools:context=".MainActivity">
    <ProgressBar
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        style="?android:attr/progressBarStyleHorizontal"
        android:id="@+id/progressbar"
        android:text="2569**"
        android:layout_gravity="center"
        android:layout_margin="10dp"
        android:max="100"
        android:progress="100"
        android:progressDrawable="@drawable/circular_progress_bar"
        android:layout_centerInParent="true"
        />
    <TextView
        android:id="@+id/textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:gravity="center"
        android:text="2678**"
        tools:text="asdasdasdas"
        android:background="#07000000"
        android:textColor="#000000"
        android:textSize="20sp" />
</RelativeLayout>

SpringBounceInterpolator

public class SpringBounceInterpolator implements android.view.animation.Interpolator {
    private double mAmplitude = 1;
    private double mFrequency = 10;

    public SpringBounceInterpolator(double amplitude, double frequency) {
        mAmplitude = amplitude;
        mFrequency = frequency;
    }

    public float getInterpolation(float time) {
        return (float) (-1 * Math.pow(Math.E, -time/ mAmplitude) *
                Math.cos(mFrequency * time) + 1);
    }
}
View view = findViewById(R.id.textview);
final Animation animation = AnimationUtils.loadAnimation(view.getContext(), R.anim.bounce);
        SpringBounceInterpolator interpolator = new SpringBounceInterpolator(0.2, 20);
        animation.setInterpolator(interpolator);
        view.startAnimation(animation);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...