zoukankan      html  css  js  c++  java
  • Android 心跳动画

    直接上代码  MainActivity  

     1 public class MainActivity extends AppCompatActivity {
     2 
     3     private ImageView ivHart;  //图片信息
     4     AlphaAnimation alphaAnimation = null;    //心跳动画
     5 
     6     @Override
     7     protected void onCreate(Bundle savedInstanceState) {
     8         super.onCreate(savedInstanceState);
     9         setContentView(R.layout.activity_main);
    10 
    11 
    12         ivHart = (ImageView) findViewById(R.id.ivHart);
    13 
    14         shadeAnim(ivHart);
    15     }
    16 
    17     @Override
    18     protected void onResume() {
    19         super.onResume();
    20         if (alphaAnimation != null) {
    21             alphaAnimation.start();
    22         }
    23     }
    24 
    25     @Override
    26     protected void onPause() {
    27         super.onPause();
    28         if (alphaAnimation != null) {
    29             alphaAnimation.cancel();
    30         }
    31     }
    32 
    33     /**
    34      * 心跳渐变动画
    35      *
    36      * @param view 执行该动画的view对象
    37      */
    38     private void shadeAnim(View view) {
    39         alphaAnimation = new AlphaAnimation(0.1f, 1.0f);
    40         alphaAnimation.setDuration(2000);
    41         alphaAnimation.setRepeatCount(-1);
    42         alphaAnimation.setRepeatMode(Animation.REVERSE);
    43         alphaAnimation.start();
    44         view.setAnimation(alphaAnimation);
    45     }

    布局文件

     1 <?xml version="1.0" encoding="utf-8"?>
     2 <RelativeLayout
     3     xmlns:android="http://schemas.android.com/apk/res/android"
     4     xmlns:tools="http://schemas.android.com/tools"
     5     android:id="@+id/activity_main"
     6     android:layout_width="match_parent"
     7     android:layout_height="match_parent"
     8      android:background="@drawable/yy"
     9     tools:context="com.hanbao.myapplication.MainActivity">
    10 
    11 
    12 
    13     <ImageView
    14         android:id="@+id/ivHart"
    15         android:layout_width="wrap_content"
    16         android:layout_height="match_parent"
    17         android:scaleType="centerCrop"
    18         android:src="@drawable/x"/>
    19 
    20 
    21 </RelativeLayout>
  • 相关阅读:
    virtmanager 的 internal error Cannot find suitable emulator for x86_64 错误
    django 判断mysql中的bit(1)
    eucalyptus volume 的一些创建流程以及理解
    将eucalyptus数据库更改为Mysql
    ftp虚拟用户添加
    通过shell读取mysql数据
    Java webservice
    axis2之webservice
    基础巩固(二) log4j的使用
    基础巩固(一)
  • 原文地址:https://www.cnblogs.com/monkey0928/p/8892801.html
Copyright © 2011-2022 走看看