温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

android空间动画

发布时间:2020-07-31 03:27:00 来源:网络 阅读:392 作者:671076656 栏目:移动开发
天在公司做项目,其中有一个模块需要让控件动起来

我再这里用到了动画

先贴出代码吧

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


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI