Android 属性动画左右移动
来源:互联网 发布:多伦多大学教育学 知乎 编辑:程序博客网 时间:2024/06/12 19:17
实现动画的左右移动,用到ObjectAnimator这个属性,要实现这个动画就要先在xml定义一个按钮,如下所示,我用到了一个背景图片,让这个背景图片左右移动
<span style="font-size:12px;"><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="${relativePackage}.${activityClass}" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="40dp" android:background="@drawable/ico" /></RelativeLayout></span>
下面就写实现背景图片左右移动的代码:
<span style="font-size:12px;">package com.example.objectanimator;import android.animation.ObjectAnimator;import android.app.Activity;import android.os.Build;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.view.animation.BounceInterpolator;import android.widget.Button;import android.widget.Toast;public class MainActivity extends Activity implements OnClickListener{private Button btn;private ObjectAnimator animator;private boolean isClick = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn = (Button) findViewById(R.id.button1); btn.setOnClickListener(this); //动画开始 if (!isClick){ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){ animator = ObjectAnimator.ofFloat(btn, "translationX", 0.0f , 20, 0f , 0f); animator.setDuration(1500);//动画时间 animator.setInterpolator(new BounceInterpolator());//实现反复移动的效果 animator.setRepeatCount(-1);//设置动画重复次数 animator.setStartDelay(1000);//设置动画延时执行 animator.start();//启动动画 } } }@Overridepublic void onClick(View v) {// TODO Auto-generated method stubswitch (v.getId()) {case R.id.button1:isClick = true;//动画结束if ( null != animator){if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){btn.post(new Runnable() {@Overridepublic void run() {// TODO Auto-generated method stubanimator.end();//动画结束}});}}Toast.makeText(MainActivity.this, "停止动画", 0).show();break;default:break;}}}</span>
0 0
- Android 属性动画左右移动
- Jquery 动画效果 左右移动
- Android移动开发-属性动画的实现
- 属性动画的移动
- javascript实现图片左右移动动画
- Android动画让两个小圆球不停地在屏幕上左右移动
- Android 悬浮窗的贴边移动及属性动画
- Android属性动画与自定义控件画圆球移动
- Android动画--属性动画
- android动画 -- 属性动画
- Android动画-属性动画
- Android动画【属性动画】
- Android动画--属性动画
- android动画-移动动画问题
- Android 移动动画- TranslateAnimation
- Android 移动动画- TranslateAnimation
- 矢量图VectorDrawable轻松实现箭头左右移动动画
- android实现页面背景的左右移动
- HTTPS和HTTP的概念和区别
- Docker
- Android Retrofit 2.0
- [Switch] VLAN-TAG超经典解释_有种豁然开朗的感觉
- Myeclips 自动补全功能失效
- Android 属性动画左右移动
- android程序中给我评分的功能
- 二维码初解
- 关于APP自动化安装(初探)
- linux安装skynet总结
- Android double保留两位小数:截取 和 四舍五入
- 面试题
- 四轴飞行器入门知识
- Nordic mem_pool