溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

android空間動(dòng)畫

發(fā)布時(shí)間:2020-07-31 03:27:00 來源:網(wǎng)絡(luò) 閱讀:404 作者:671076656 欄目:移動(dòng)開發(fā)
天在公司做項(xiàng)目,其中有一個(gè)模塊需要讓控件動(dòng)起來

我再這里用到了動(dòng)畫

先貼出代碼吧

//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" />

//動(dòng)畫路徑 res/anim/tip.xml

 

 

   

        android:fromDegrees="0"  

        android:toDegrees="359"  

        android:duration="1000"  

        android:repeatCount="-1"  

        android:pivotX="50%"  

        android:pivotY="50%" />  

 

動(dòng)畫的參數(shù)設(shè)置:

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

        android:toDegrees="359"   //結(jié)束的角度度數(shù),負(fù)數(shù)表示逆時(shí)針,正數(shù)表示順時(shí)針。如2圈則比  //android:fromDegrees大720即可

        android:duration="1000"    //表示從android:fromDegrees轉(zhuǎn)動(dòng)到android:toDegrees所花費(fèi)的時(shí)間,    //單位為毫秒??梢杂脕碛?jì)算速度。

        android:repeatCount="-1"  //重復(fù)的次數(shù),負(fù)數(shù)表示一直旋轉(zhuǎn)

        android:pivotX="50%"      //旋轉(zhuǎn)中心的坐標(biāo)

        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("關(guān)閉");

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("關(guān)閉");

stopAnimation();

}

}

});

}

public void startAnimation(){

if (operatingAnim != null) {  

    imgbtn.startAnimation(operatingAnim);  

}  

}

public void stopAnimation(){

imgbtn.clearAnimation();

}

}                       

android空間動(dòng)畫


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI