4.4.3 Android animation制作 跳动的心

0: 首先还是在res 下面创建一个anim的文件夹

然后创建一个resource 的文件 名为size.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:duration="2000"
    android:pivotX="50%"
    android:pivotY="50%"
    android:fromXScale="1"
    android:fromYScale="1"
    android:toXScale="1.2"
    android:toYScale="1.2"
    android:interpolator="@android:interpolator/bounce"
    android:repeatMode="reverse"
    android:repeatCount="infinite"/>
    <alpha android:repeatCount="infinite"
        android:duration="2000"
        android:fromAlpha="0.1"
        android:toAlpha="1"
        android:repeatMode="reverse"
        />
</set>

图片如下:



1:布局里面

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

    <ImageView
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_centerInParent="true"
        android:onClick="imageSize"
        android:src="@mipmap/heart"
        android:id="@+id/image_scale"/>
</RelativeLayout>


2:MainActivity 文件:

package tech.androidstudio.animationdemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements Animation.AnimationListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }


    public void imageSize(View view) {
        ImageView image_scale = (ImageView) findViewById(R.id.image_scale);
        Animation animation = AnimationUtils.loadAnimation(this,R.anim.size);
        image_scale.startAnimation(animation);
    }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值