资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

android空间动画

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

我再这里用到了动画

网站建设哪家好,找创新互联!专注于网页设计、网站建设、微信开发、重庆小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了紫金免费建站欢迎大家使用!

先贴出代码吧

//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空间动画


文章标题:android空间动画
链接URL:http://cdkjz.cn/article/jsoepc.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220