天在公司做项目,其中有一个模块需要让控件动起来

我再这里用到了动画

先贴出代码吧

//layout

android:layout_width="match_parent"

android:layout_height="match_parent" >

android:id="@+id/imgpic"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:scaleType="center"

android:src="@drawable/left" >//图片可更改

android:id="@+id/toggleButton1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

android:layout_centerHorizontal="true"

android:layout_marginBottom="141dp"

android:text="ToggleButton" />

//动画路径 res/anim/tip.xml

android:fromDegrees="0"

android:toDegrees="359"

android:duration="1000"

android:repeatCount="-1"

android:pivotX="50%"

android:pivotY="50%" />

动画的参数设置:

android:fromDegrees="0" //起始角度

android:toDegrees="359" //结束的角度度数,负数表示逆时针,正数表示顺时针。如2圈则比 //android:fromDegrees大720即可

android:duration="1000" //表示从android:fromDegrees转动到android:toDegrees所花费的时间//单位为毫秒。可以用来计算速度。

android:repeatCount="-1" //重复的次数,负数表示一直旋转

android:pivotX="50%" //旋转中心的坐标

android:pivotY="50%" />

//activity

package com.example.pictween;

import android.os.Bundle;

import android.app.Activity;

import android.view.Menu;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.animation.Animation;

import android.view.animation.AnimationUtils;

import android.view.animation.LinearInterpolator;

import android.widget.ImageButton;

import android.widget.Toast;

import android.widget.ToggleButton;

public class MainActivity extends Activity {

private Animation operatingAnim;

private ToggleButton togbtn;

private boolean flag = false;

private ImageButton imgbtn;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

togbtn = (ToggleButton) findViewById(R.id.toggleButton1);

togbtn.setText("关闭");

imgbtn = (ImageButton) findViewById(R.id.imgpic);

operatingAnim = AnimationUtils.loadAnimation(this, R.anim.tip);

LinearInterpolator lin = new LinearInterpolator();

operatingAnim.setInterpolator(lin);

togbtn.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View arg0) {

// TODO Auto-generated method stub

flag = !flag;

if(flag){

togbtn.setText("开启");

startAnimation();

}else{

togbtn.setText("关闭");

stopAnimation();

}

}

});

}

public void startAnimation(){

if (operatingAnim != null) {

imgbtn.startAnimation(operatingAnim);

}

}

public void stopAnimation(){

imgbtn.clearAnimation();

}

}

android空间动画


更多相关文章

  1. android添加动画效果
  2. Android抖动的动画效果
  3. Android animation Interpolator属性 设置动画速度介绍?
  4. android仿漫画源码、抽奖转盘、Google相册、动画源码等
  5. 自定义android开机动画
  6. 自定义动画(animation)时set中的各元素效果
  7. android源码下载-等待提示动画
  8. Android 属性动画(Property Animation) 完全解析 (下)
  9. Android 实现动画方式

随机推荐

  1. android UI设计的小技巧
  2. android 视图getParent,getChildAt
  3. Android(安卓)微信SDK分享功能(一)
  4. Android--RelativeLayout
  5. 双击运行Android模拟器、创建SDcard、AVD
  6. Android: MediaScanner生成thumbnail的算
  7. Android 中的AsyncTask的使用心得
  8. Android总结与展望:2012成为王者,2013再创
  9. android视图层的设计 javacode版本 有图
  10. Android Studio添加第三方库遇到的一些坑