在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. [SQL]SQL语言入门级教材_SQL语法参考手册(三)

    SQL 语法参考手册 DB2 提供了关连式资料库的查询语言 SQL (Structured Query Language),是一种非常口语化.既易学又易懂的语法. 此语言几乎是每个资料库系统都必须提供 ...

  2. Sq server 关于存储过程,触发器的一些理论简述

    http://www.doc88.com/p-2905916227462.html      

  3. Xpath定位大全

    selenium使用Xpath定位之完整篇   其中有一片文章提到了xpath元素定位,但是该文章中有些并不能适应一些特殊与个性化的场景.在文本中提供xpath元素的定位终极篇,你一定能在这里找到你需 ...

  4. ApplePay

    ApplePay要在项目有里配置,,配置好项目之后,就剩下编码了,做ApplePay首先要检查设备是否支持ApplePay,支持 ApplePay的设备在 iPhone6及以后,  PKPayment ...

  5. Microsoft Visual C++ 2010(86) Redistributable不能安装完美解决

    见http://jingyan.baidu.com/article/9c69d48f41aa6313c9024ebe.html 1. 去mircosoft下载安装包(vcredist_x64.exe) ...

  6. USACO Section 4.4 追查坏牛奶Pollutant Control

    http://www.luogu.org/problem/show?pid=1344 题目描述 你第一天接手三鹿牛奶公司就发生了一件倒霉的事情:公司不小心发送了一批有三聚氰胺的牛奶.很不幸,你发现这件 ...

  7. Java EXCEL导入的两种方式JXL和POI

    Excel导入有两个方法:JXL 和POI 1.JXL解析Excel public class JxlReadExcel { /**     * JXL解析Excel     * @author Da ...

  8. form表单 无法提交js动态添加的表单元素问题。。

    第一种情况, 这种情况js动态添加的表单元素是不能提交到服务器端的 <table> <form method="post" action=" url   ...

  9. centos下的防火墙配置

    1,查看防火墙文件: vim /etc/sysconfig/iptables # Generated by iptables-save v1. :: *filter :INPUT ACCEPT [:] ...

  10. 不安装Oracle客户端使用PL/SQL连接服务器端Oracle

    从10G开始,Oracle 提供了一个较为轻量级的客户包,叫做Instant Client Package. 将它安装好后,就不用再安装庞大的Oracle客户端,可以直接通过使用PL/SQL连接服务器 ...