animation 控件之代码控制
来源:互联网 发布:淘宝售后怎么赚钱 编辑:程序博客网 时间:2024/06/01 18:49
Q群: 241359063 更精彩,欢迎共同走向创业学习之旅。
原创:kylin_zeng http://blog.chinaunix.net/uid/23795897.html在此感谢mars 老师的帮助。转载请注明原创出处,尊重他人的劳动成果。
1、animations 提供一个动画的效果。
2、animation 分成两类:
第一类: Tweened Animations,提供旋转Rotate,移动Translate,伸展缩放Scale,淡入淡出Alpha.
第二类: Frame-by-Frame animation. 这类可以创建一个drawable 系列,可以按照指定时间间隔显示。
3、第一类详解:步骤:
3.1 创建一个AnimationSet 对象;
3.2 根据需要创建队友的Animation 对象;
3.3 根据软件动画的需要为Animation对象设置对应的数据。
3.4 将Animation 对象添加到AnimationSet 对象里面。
3.5 使用空间对象开始执行AnimationSet.
创建ImageView图片来查看效果:
<ImageView android:id="@+id/imageViewId"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerInParent="true" android:layout_marginTop="100dip"
android:src="@drawable/icon" />
1、创建几个按钮来控制:
2、
02_08.zip
原创:kylin_zeng http://blog.chinaunix.net/uid/23795897.html在此感谢mars 老师的帮助。转载请注明原创出处,尊重他人的劳动成果。
1、animations 提供一个动画的效果。
2、animation 分成两类:
第一类: Tweened Animations,提供旋转Rotate,移动Translate,伸展缩放Scale,淡入淡出Alpha.
第二类: Frame-by-Frame animation. 这类可以创建一个drawable 系列,可以按照指定时间间隔显示。
3、第一类详解:步骤:
3.1 创建一个AnimationSet 对象;
3.2 根据需要创建队友的Animation 对象;
3.3 根据软件动画的需要为Animation对象设置对应的数据。
3.4 将Animation 对象添加到AnimationSet 对象里面。
3.5 使用空间对象开始执行AnimationSet.
创建ImageView图片来查看效果:
<ImageView android:id="@+id/imageViewId"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerInParent="true" android:layout_marginTop="100dip"
android:src="@drawable/icon" />
1、创建几个按钮来控制:
点击(此处)折叠或打开
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical" android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <Button android:id="@+id/scaleButtonId" android:layout_width="fill_parent"
- android:layout_height="wrap_content" android:layout_alignParentBottom="true"
- android:text="测试scale动画效果" />
-
- <Button android:id="@+id/rotateButtonId" android:layout_width="fill_parent"
- android:layout_height="wrap_content" android:layout_above="@id/scaleButtonId"
- android:text="测试rotate动画效果" />
-
- <Button android:id="@+id/alphaButtonId" android:layout_width="fill_parent"
- android:layout_height="wrap_content" android:layout_above="@id/rotateButtonId"
- android:text="测试alpha动画效果" />
- <Button android:id="@+id/translateButtonId"
- android:layout_width="fill_parent" android:layout_height="wrap_content"
- android:layout_above="@id/alphaButtonId" android:text="测试translate动画效果" />
-
- <LinearLayout android:orientation="vertical"
- android:layout_width="fill_parent" android:layout_height="fill_parent">
- <ImageView android:id="@+id/imageViewId"
- android:layout_width="wrap_content" android:layout_height="wrap_content"
- android:layout_centerInParent="true" android:layout_marginTop="100dip"
- android:src="@drawable/icon" />
- </LinearLayout>
- </RelativeLayout>
2、
点击(此处)折叠或打开
- package mars.animations01;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.animation.AlphaAnimation;
- import android.view.animation.Animation;
- import android.view.animation.AnimationSet;
- import android.view.animation.RotateAnimation;
- import android.view.animation.ScaleAnimation;
- import android.view.animation.TranslateAnimation;
- import android.widget.Button;
- import android.widget.ImageView;
- public class MainActivity extends Activity {
- /** Called when the activity is first created. */
- private ImageView imageView = null;
- private Button rotateButton = null;
- private Button scaleButton = null;
- private Button alphaButton = null;
- private Button translateButton = null;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- imageView = (ImageView) findViewById(R.id.imageViewId);
- rotateButton = (Button) findViewById(R.id.rotateButtonId);
- rotateButton.setOnClickListener(new RotateButtonListener());
- scaleButton = (Button) findViewById(R.id.scaleButtonId);
- scaleButton.setOnClickListener(new ScaleButtonListener());
- alphaButton = (Button) findViewById(R.id.alphaButtonId);
- alphaButton.setOnClickListener(new AlphaButtonListener());
- translateButton = (Button) findViewById(R.id.translateButtonId);
- translateButton.setOnClickListener(new TranslateButtonListener());
- }
- private class RotateButtonListener implements OnClickListener {
- @Override
- public void onClick(View view) {
- AnimationSet animationSet = new AnimationSet(true);
- RotateAnimation rotateAnimation = new RotateAnimation(0, 360, /*从0旋转到360度*/
- Animation.RELATIVE_TO_PARENT, 1f, /*x轴以父控件为参照物,1f -> 从0~1,如果是0.5表示一半*/
- Animation.RELATIVE_TO_PARENT, 0f); /*y轴以父控件为参照物,0f -> 从0~1,如果是0.5表示一半*/
- rotateAnimation.setDuration(5000); //持续时间5000ms
- animationSet.addAnimation(rotateAnimation);
- imageView.startAnimation(animationSet);
- }
- }
- private class ScaleButtonListener implements OnClickListener {
- @Override
- public void onClick(View view) {
- AnimationSet animationSet = new AnimationSet(true);
- ScaleAnimation scaleAnimation = new ScaleAnimation(1, 0.1f, 1, 0.5f, /*1,0.1f, x轴从1到10%。 1,0.5f, y轴从1到0.5*/
- Animation.RELATIVE_TO_SELF, 0.5f,
- Animation.RELATIVE_TO_SELF, 0.5f);
- animationSet.addAnimation(scaleAnimation);
- animationSet.setStartOffset(1000);
- animationSet.setFillAfter(true);
- animationSet.setFillBefore(false);
- animationSet.setDuration(2000);
- imageView.startAnimation(animationSet);
- }
- }
- private class AlphaButtonListener implements OnClickListener {
- @Override
- public void onClick(View view) {
- //创建一个AnimationSet对象
- AnimationSet animationSet = new AnimationSet(true);
- //创建一个AlphaAnimation对象
- AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
- //设置动画执行的时间(单位:毫秒)
- alphaAnimation.setDuration(1000);
- //将AlphaAnimation对象添加到AnimationSet当中
- animationSet.addAnimation(alphaAnimation);
- //使用ImageView的startAnimation方法开始执行动画
- imageView.startAnimation(animationSet);
- }
- }
- private class TranslateButtonListener implements OnClickListener {
- @Override
- public void onClick(View view) {
- AnimationSet animationSet = new AnimationSet(true);
- TranslateAnimation translateAnimation = new TranslateAnimation(
- Animation.RELATIVE_TO_SELF, 0f, /*x轴移动开始值*/
- Animation.RELATIVE_TO_SELF, 0.5f, /*x轴移动后的值*/
- Animation.RELATIVE_TO_SELF, 0f, /*y轴移动开始值*/
- Animation.RELATIVE_TO_SELF, 1.0f); /*y轴移动后的值*/
- translateAnimation.setDuration(1000);
- animationSet.addAnimation(translateAnimation);
- imageView.startAnimation(animationSet);
- }
- }
- }
02_08.zip
0
上一篇: linux文件系统启动流程
下一篇:Ubuntu文件系统层 系统启动过程详解
相关热门文章
- Android之开发环境搭建
- Android自定义View的实现...
- AndroidManifest.xml配置文件...
- Android源码调试方法详解...
- 不用vs和cygwin!Eclipse+cdt...
- 请问Linux默认shell的是什么 ...
- 谁能够帮我解决LINUX 2.6 10...
- 现在的博客积分不会更新了吗?...
- shell怎么读取网页内容...
- ssh等待连接的超时问题...
给主人留下些什么吧!~~
评论热议
0 0
- animation 控件之代码控制
- animation 之xml控制
- Android动画控件之Animation
- animation 之动画时间的控制
- animation之二,使用xml控制animat…
- TextBox控件之读控制
- Animation之View Animation
- Animation之Property Animation
- Animation之View Animation
- Android的Animation之LayoutAnimation使用方法(控件设置动画)
- 代码控制控件可用性和可见性
- ios 代码控制出现控件的阴影
- cocos2d animation 时间控制
- JS控制animation事件
- Android动画Animation之Tween用代码实现动画效果
- Ajax控件使用--Animation
- Android Animation之frame animation
- HTControl之CHTSlider控制杆控件类
- git 命令
- android service传递并获取参数 之 transact
- 软件安装原理
- linux文件系统启动流程
- C/C++面试、笔试题
- animation 控件之代码控制
- Ubuntu文件系统层 系统启动过程详解
- 系统需求与功能需求有什么区别
- animation 之xml控制
- 1st_uC/OS-II Basic Programmers’Guide
- animation 之动画时间的控制
- animations 动画图片的播放
- 跟我一起学extjs5(06--使用图标字体来美化按钮)
- animations 之 对控件设置动画效果
原创粉丝点击
热门IT博客
热门问题
老师的惩罚
人脸识别
我在镇武司摸鱼那些年
重生之率土为王
我在大康的咸鱼生活
盘龙之生命进化
天生仙种
凡人之先天五行
春回大明朝
姑娘不必设防,我是瞎子
东风风神suv
东风7座
东风商务
东风日产7座
东风车
东风商务车
东风汽车suv
东风越野
东风卡车
东风货车
东风系列
东风轿车
suv东风
东风轿跑
东风气车
东风轿跑车
东风跑车
东风风度
东风sx6
东风x6
东风mx6
东风mx5
mx6东风风度
东风日产mx6
东风风度mx7
东风客车
东风5
东风小霸王
东风x5
东风悍马
东风重卡
东风车标
东风标志
东风微面
东风面包
东风一汽
日产东风
东风1号
东风轻卡
东风自卸车
东风a9价格