How to create ImageView pulse effect using nine old androids animation

后端 未结 3 1446
悲哀的现实
悲哀的现实 2021-01-30 08:57

I wonder how I should create a pulse effect using nine olad androids framework animation.

To understand better lets say you have an ImageView and want to have a \"pulse\

相关标签:
3条回答
  • 2021-01-30 09:33

    to use @ Matthias Robbers solution directly from the XML, you can do the following: create 2 files:

    1- pulse.xml

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android">
        <scale xmlns:android="http://schemas.android.com/apk/res/android"
            android:fromXScale="1"
            android:fromYScale="1"
            android:pivotX="50%"
            android:pivotY="50%"
            android:toXScale="0.8"
            android:toYScale="0.8"
            android:duration="500"
            android:repeatCount="infinite"
            android:repeatMode="reverse"/>
    </set>
    

    2- pulse_layout_animation.xml

    <?xml version="1.0" encoding="utf-8"?>
    <layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
        android:animation="@anim/pulse">
    </layoutAnimation>
    

    then in your layout xml file just add this animation to any view you need, for example:

    <ImageView
        android:layout_width="55dp"
        android:layout_height="55dp"
        android:src="@drawable/heart"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layoutAnimation="@anim/pulse_layout_animation" />
    
    0 讨论(0)
  • 2021-01-30 09:38

    R.anim.pulse:

    <scale xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="1000"
        android:fromXScale="1"
        android:fromYScale="1"
        android:pivotX="50%"
        android:pivotY="50%"
        android:repeatCount="1"
        android:repeatMode="reverse"
        android:toXScale="0.5"
        android:toYScale="0.5" />
    
    ImageView imageView = (ImageView) findViewById(R.id.image);
    Animation pulse = AnimationUtils.loadAnimation(this, R.anim.pulse);
    imageView.startAnimation(pulse);
    
    0 讨论(0)
  • 2021-01-30 09:41

    heart_pulse.xml put heart_pulse.xml in res/anim folder Add android:interpolator

    then use in your activity like below

    <?xml version="1.0" encoding="utf-8"?>
    <scale xmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:fromXScale="1"
        android:fromYScale="1"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="0.5"
        android:toYScale="0.5"
        android:duration="1000"
        android:repeatCount="infinite"
        android:repeatMode="reverse"/>
    
    ImageView imageView =(ImageView)findViewById(R.id.imageView);
    Animation pulse = AnimationUtils.loadAnimation(this, R.anim.heart_pulse);
    imageView.startAnimation(pulse);
    
    0 讨论(0)
提交回复
热议问题