在res中建立文件夹anim,分别写下cycles.xml,shake1.xml,shake2.xml

cycles.xml:

 <?xml version="1.0" encoding="utf-8"?>
<!-- android:cycles代表移动的速度 -->
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
android:cycles="1" />

shake1.xml:

 <?xml version="1.0" encoding="utf-8"?>
<!--水平移动 -->
<!--android:duration代表运行时间 -->
<!-- android:fromXDelta代表起始横坐标位置 (0,0)-->
<!-- android:toXDelta代表离横坐标起始位置的X距离为100 (100,0)-->
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="3000"
android:fromXDelta="0.0"
android:toXDelta="100.0"
android:interpolator="@anim/cycles"/>

shake2.xml:

 <?xml version="1.0" encoding="utf-8"?>
<!--垂直移动 -->
<!--android:duration代表运行时间 -->
<!-- android:fromXDelta代表起始纵坐标位置 (0,0)-->
<!-- android:toXDelta代表离横坐标起始位置的Y距离为100(0,100)-->
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="3000"
android:fromYDelta="0.0"
android:toYDelta="100.0"
android:interpolator="@anim/cycles"/>

activity_main.xml:

 1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2 xmlns:tools="http://schemas.android.com/tools"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 tools:context="com.zzw.testshake.MainActivity" >
6
7 <ImageView
8 android:id="@+id/image2"
9 android:layout_width="100dp"
10 android:layout_height="100dp"
11 android:layout_alignParentBottom="true"
12 android:layout_centerHorizontal="true"
13 android:layout_marginBottom="78dp"
14 android:src="@drawable/b" />
15
16 <ImageView
17 android:id="@+id/image1"
18 android:layout_width="100dp"
19 android:layout_height="100dp"
20 android:layout_alignLeft="@+id/image2"
21 android:layout_alignParentTop="true"
22 android:layout_marginTop="87dp"
23 android:src="@drawable/a" />
24
25 <Button
26 android:id="@+id/button2"
27 style="?android:attr/buttonStyleSmall"
28 android:layout_width="wrap_content"
29 android:layout_height="wrap_content"
30 android:layout_above="@+id/image2"
31 android:layout_toLeftOf="@+id/image2"
32 android:text="Button" />
33
34
35 <Button
36 android:id="@+id/button1"
37 style="?android:attr/buttonStyleSmall"
38 android:layout_width="wrap_content"
39 android:layout_height="wrap_content"
40 android:layout_below="@+id/editText1"
41 android:layout_toLeftOf="@+id/image1"
42 android:text="Button" />
43
44 </RelativeLayout>

activity_main.xml

MainActivity:

 package com.zzw.testshake;

 import android.app.Activity;
import android.os.Bundle;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); ImageView image1 = (ImageView) findViewById(R.id.image1);
image1.startAnimation(AnimationUtils.loadAnimation(this, R.anim.shake1)); ImageView image2 = (ImageView) findViewById(R.id.image2);
image2.startAnimation(AnimationUtils.loadAnimation(this, R.anim.shake2)); Button bt1 = (Button) findViewById(R.id.button1);
bt1.startAnimation(AnimationUtils.loadAnimation(this, R.anim.shake1)); Button bt2 = (Button) findViewById(R.id.button2);
bt2.startAnimation(AnimationUtils.loadAnimation(this, R.anim.shake2)); } }

怎样使android的view动画循环弹动的更多相关文章

  1. Android开发——View动画、帧动画和属性动画详解

    0. 前言   Android动画是面试的时候经常被问到的话题.我们都知道Android动画分为三类:View动画.帧动画和属性动画. 先对这三种动画做一个概述: View动画是一种渐进式动画,通过图 ...

  2. Android传统View动画与Property动画基础及比较

    前言:关于动画方面的知识也整理一段时间了,如题,这篇文章简单的介绍了View和Property动画的概念,如何在项目中创建资源文件,以及如何在代码中使用它们,本次整理动画的重点放在了Property动 ...

  3. Android(java)学习笔记200:Android中View动画之 XML实现 和 代码实现

    1.Animation 动画类型 Android的animation由四种类型组成: XML中: alph 渐变透明度动画效果 scale 渐变尺寸伸缩动画效果 translate 画面转换位置移动动 ...

  4. Android(java)学习笔记143:Android中View动画之 XML实现 和 代码实现

    1.Animation 动画类型 Android的animation由四种类型组成: XML中: alph 渐变透明度动画效果 scale 渐变尺寸伸缩动画效果 translate 画面转换位置移动动 ...

  5. Android移动view动画问题

    http://www.cnblogs.com/eoiioe/archive/2012/08/29/2662546.html Android写动画效果不是一般的麻烦,网上找了好久,终于解决了动画的问题, ...

  6. Android中view动画

    [1]透明 //点击按钮 实现iv 透明的效果 动画 public void click1(View v) { //1.0意味着着完全不透明 0.0意味着完全透明 AlphaAnimation aa ...

  7. Android中的动画学习总结

    android中动画可分为三种:帧动画,补间动画,和属性动画.其中属性动画是google推荐的,它可以实现前面两种动画的效果,运用起来更加灵活. 帧动画:顾名思义,就是一帧一帧的图片,快速播放形成的动 ...

  8. Android中的动画使用总结

    android中动画可分为三种:帧动画,补间动画,和属性动画.其中属性动画是google推荐的,它可以实现前面两种动画的效果,运用起来更加灵活. 帧动画:顾名思义,就是一帧一帧的图片,快速播放形成的动 ...

  9. android 巧用动画使您app风骚起来

    巧用Android的自定义动画,使你更加的有动感,是大多数Android开发人员的目标,那怎么做到这点.请听下文分解: 3.0以前,android支持两种动画模式,tween animation(幅间 ...

随机推荐

  1. T4 模板的调试方法,方便大家遇到问题自己快速定位和优化

    T4 模板的调试方法,方便大家遇到问题自己快速定位和优化 :1. .ttinclude文件的第一行修改为 <#@ template language="C#" debug=& ...

  2. 百度地图API 学习网站

    官方示例:http://developer.baidu.com/map/jsdemo.htm#a1_2 (注意:此网页可能由于浏览器问题,源代码编辑器中的代码不能看到.火狐亲测有效) http://d ...

  3. 这些优化 Drupal 网站速度的超简单办法,你忽略了多少?

    “怎么样能让我的 Drupal 网站更快一些?”是我们最常遇到的一个问题.站点速度确实非常重要,因为它会影响你的 SEO排名效果.访客是否停留以及你自己管理网站所需要的时间. 今天我们就来看看那些通过 ...

  4. centos 6.5 samba简单配置

    1.安装samba yum -y install samba  (我的显示已经安装啦!) 2.编辑samba的配置文件 vi /etc/samba/smb.conf 用 testparm查看我配置后的 ...

  5. Android网络编程之Socket

    Socket(套接字)是一种通信机制,可以实现单机或跨网络进行通信,其创建需要明确的区分C(客户端)/S(服务器端),支持多个客户端连接到同一个服务器.有两种传输模式: 1).面向连接的传输:基于TC ...

  6. 学习总结 java 父子级

    package com.hanqi; //父类 public class Father { // public Father() // { // // } // public Father(Strin ...

  7. 如何利用百度地图JSAPI画带箭头的线?

    百度地图JSAPI提供两种绘制多折线的方式,一种是已知多折线经纬度坐标串通过AddOverlay接口进行添加:另一种是通过在地图上鼠标单击进行绘制(鼠标绘制工具条库).目前这两种方式只能绘制多折线,并 ...

  8. RHEL7网卡设置

    1.改网卡名 先vim /etc/sysconfig/grub:GRUB_TIMEOUT=5GRUB_DEFAULT=savedGRUB_DISABLE_SUBMENU=trueGRUB_TERMIN ...

  9. ZoneMinder配置与使用

    ZoneMinder是一套基于Linux操作系统的摄像机的视像数据监控的应用软件.应用范围广泛,包括商业或家居防盗等.ZoneMinder支持单一或多台视像镜头应用,包括摄取.分析.记录.和监视来源, ...

  10. Struts2使用ModelDriven后JSON数据返回不正确

    在struts.xml中加入<param name="root">action</param> <result name="exist&qu ...