android空间动画-创新互联

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

我再这里用到了动画

10年积累的成都网站制作、网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先建设网站后付款的网站建设流程,更有梅州免费网站建设让你可以放心的选择与我们合作。

先贴出代码吧

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

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前文章:android空间动画-创新互联
链接URL:http://lszwz.com/article/esisj.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款