怎样使android的view动画循环弹动
在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动画循环弹动的更多相关文章
- Android开发——View动画、帧动画和属性动画详解
0. 前言 Android动画是面试的时候经常被问到的话题.我们都知道Android动画分为三类:View动画.帧动画和属性动画. 先对这三种动画做一个概述: View动画是一种渐进式动画,通过图 ...
- Android传统View动画与Property动画基础及比较
前言:关于动画方面的知识也整理一段时间了,如题,这篇文章简单的介绍了View和Property动画的概念,如何在项目中创建资源文件,以及如何在代码中使用它们,本次整理动画的重点放在了Property动 ...
- Android(java)学习笔记200:Android中View动画之 XML实现 和 代码实现
1.Animation 动画类型 Android的animation由四种类型组成: XML中: alph 渐变透明度动画效果 scale 渐变尺寸伸缩动画效果 translate 画面转换位置移动动 ...
- Android(java)学习笔记143:Android中View动画之 XML实现 和 代码实现
1.Animation 动画类型 Android的animation由四种类型组成: XML中: alph 渐变透明度动画效果 scale 渐变尺寸伸缩动画效果 translate 画面转换位置移动动 ...
- Android移动view动画问题
http://www.cnblogs.com/eoiioe/archive/2012/08/29/2662546.html Android写动画效果不是一般的麻烦,网上找了好久,终于解决了动画的问题, ...
- Android中view动画
[1]透明 //点击按钮 实现iv 透明的效果 动画 public void click1(View v) { //1.0意味着着完全不透明 0.0意味着完全透明 AlphaAnimation aa ...
- Android中的动画学习总结
android中动画可分为三种:帧动画,补间动画,和属性动画.其中属性动画是google推荐的,它可以实现前面两种动画的效果,运用起来更加灵活. 帧动画:顾名思义,就是一帧一帧的图片,快速播放形成的动 ...
- Android中的动画使用总结
android中动画可分为三种:帧动画,补间动画,和属性动画.其中属性动画是google推荐的,它可以实现前面两种动画的效果,运用起来更加灵活. 帧动画:顾名思义,就是一帧一帧的图片,快速播放形成的动 ...
- android 巧用动画使您app风骚起来
巧用Android的自定义动画,使你更加的有动感,是大多数Android开发人员的目标,那怎么做到这点.请听下文分解: 3.0以前,android支持两种动画模式,tween animation(幅间 ...
随机推荐
- ZOJ 2404 Going Home 【最小费用最大流】
思路: 把房子和人看成点,加上源点和汇点. 源点和每个人连容量为1,权值为0的边. 每个人和每个房子连容量为1,权值为距离的边. 每个房子和汇点连容量为1,权值为0的边. #include<st ...
- C++primer 练习15.15
// 15_15.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...
- 【原】基于64位Centos6.2的mcrouter使用简介
此文转载必须注明原文地址,请尊重作者的劳动成果! http://www.cnblogs.com/lyongerr/p/5040071.html 目录 文档控制... 2 1 mcrouter简介.. ...
- 《Head First 设计模式》ch.3 装饰(Decorator)模式
设计原则 类应该对修改关闭,对扩展开放(开放-关闭原则).在每个地方使用开放-关闭原则是一种浪费,也没有必要,因为这通常会引入新的抽象层次,增加代码复杂度.需要把注意力集中在设计中最有可能改变的地方. ...
- MFC中,如何自定义用户消息
1.用处 在多个类之间传递消息.当需要响应用户操作,本类却无法实现时,可以向系统发出消息.然后让系统中的需要的位置实现它. 2.方法 2.1定义这个消息,并让拥有者发送这个这个消息,传递一个整型参数 ...
- appium的xpath定位
做自动化,元素定位是我们遇到的第一个困难.总是会有各种各样的问题,导致我们定位不到元素.前面一篇博客也写了元素定位的几种方法,今天主要分享一下xpath的定位方法. 这里我们仍然拿计算器举例. 比如我 ...
- 置换贴图 Displacement Mapping
视差贴图和法线贴图都是使用特定的手段来达到欺骗视觉的目的,让人以为物体的表面是凹凸起伏的.而置换贴图却是真的将模型的顶点进行偏移,在原本的平面上创造出凹凸的效果.既然是对顶点进行偏移,那么就需要模型有 ...
- VIM安装 NERDTREE,SOLARIZED 插件
实验系统版本及VIM版本 系统:CentOS6.3 VIM:7.2 插件介绍 (附上一张效果图) nerdtree(在窗口左侧用于浏览目录结构的插件) solarized(一个自己认为比较护眼的vim ...
- 【LeetCode】16. 3Sum Closest
题目: Given an array S of n integers, find three integers in S such that the sum is closest to a given ...
- 【MySQL】MySQL索引背后的之使用策略及优化【转】
转自:http://database.ctocio.com.cn/353/11664853.shtml 另外很不错的对于索引及索引优化的文章: http://www.cnblogs.com/magia ...