怎样使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(幅间 ...
随机推荐
- POJ 2516 Minimum Cost [最小费用最大流]
题意略: 思路: 这题比较坑的地方是把每种货物单独建图分开算就ok了. #include<stdio.h> #include<queue> #define MAXN 500 # ...
- java网格布局管理器
public class GirdLayoutPosition extends JFrame{ public GirdLayoutPosition() { Container ...
- 针对android方法数64k的限制,square做出的努力。精简protobuf
1.早期的Dalvik VM内部使用short类型变量来标识方法的id,dex限制了程序的最大方法数是65535,如果超过最大限制,无法编译,把dex.force.jumbo=true添加到proje ...
- zabbix通过sendmail进行邮箱警报
安装sendmail /usr/lib/zabbix/alertscripts/SendEmail.sh #!/bin/bash to_email_address="$1" # 收 ...
- iOS UIButton 设置图片文字垂直排列
后面经过测试,如果button的文字长度变更,会导致图片位置变化,经过多次修改UIEdgeInsets的值也没有达到期望效果,最终采用集成UIButton类,重写layoutSubviews函数实现, ...
- OC基础(25)
NSNumber NSValue NSDate NSFileManager *:first-child { margin-top: 0 !important; } body > *:last-c ...
- 《Head First 设计模式》ch.1 策略(Strategy)模式
策略模式 定义了算法族,分别封装起来,让它们可以互相替换,让算法的变化独立于使用算法的客户. 模式名词的意义 威力强大,交流的不止是模式名称,而是一整套模式背后所象征的质量.特性.约束 用更少的词汇做 ...
- DP走方格型
Hrbust 1812 http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=1812 有 ...
- 怎样用CODESOFT打印连续的条码标签?
在实际工作中,经常会用CODESOFT条 码打印软件来实现打印连续的条码标签,将这些标签按递增或递减等方式连续打印.这样设置可大大提高用户的工作效率.实现在CODESOFT 2015打印连续条码标签, ...
- Git 图解剖析
git中文件内容并没有真正存储在索引(.git/index)或者提交对象中,而是以blob的形式分别存储在数据库中(.git/objects),并用SHA-1值来校验. 索引文件用识别码列出相关的bl ...