安卓動畫基礎講解

來源:互聯網
上載者:User

標籤:


//逐幀動畫
/**
* 1.加入單張圖片
* 2.產生movie.xml整個圖片
* 3.代碼中使用圖片movie.xml
*/
iv=(ImageView) findViewById(R.id.iv);
//iv.setImageResource(R.drawable.movie);//為iv載入六張圖片
//AnimationDrawable ad=(AnimationDrawable) iv.getDrawable();//得到圖片給動畫圖片
//ad.start();

DisplayMetrics dm = new DisplayMetrics();
getWindow().getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;//得到螢幕寬度

//補間動畫,平移
//1.通過代碼直接寫
//Animation translate=new TranslateAnimation(0, width, 0, 0);
//translate.setDuration(2000);
//translate.setFillAfter(true);//動畫完成後,留在原位

//translate.setRepeatCount(2);//重複2次
//translate.setStartOffset(1000);//等待1秒後再動

//iv.startAnimation(translate);

//2.調用xml檔案
Animation translate=AnimationUtils.loadAnimation(this, R.anim.push_to_right);
iv.startAnimation(translate);
//iv.setAnimation(translate);也行

//動畫監聽事件
translate.setAnimationListener(new AnimationListener() {

@Override
public void onAnimationStart(Animation animation) {

}

@Override
public void onAnimationRepeat(Animation animation) {

}

@Override
public void onAnimationEnd(Animation animation) {
Intent intent=new Intent(MainActivity.this,SecondAty.class);
startActivity(intent);
finish();

}
});

}

 

// 旋轉動畫
// 角度從0到360,pivotXType取誰的X值(介面的?就自身這個圖片) pivotYType
// Animation rotator = new RotateAnimation(0, 360,
// RotateAnimation.RELATIVE_TO_SELF, 0.5f,
// RotateAnimation.RELATIVE_TO_SELF, 0.5f);
// rotator.setDuration(3000);
// rotator.setFillAfter(true);
// iv.startAnimation(rotator);

// 漸層
// Animation alpha = new AlphaAnimation(0, 0.9f);//從看不見到看到90%
// alpha.setDuration(3000);
// alpha.setFillAfter(true);
// iv.startAnimation(alpha);

// 展開
// fromX, toX, fromY, toY平移動畫的四個參數,x軸伸縮尺寸,y軸伸縮尺寸
//ScaleAnimation.RELATIVE_TO_SELF, 3f//X軸座標是自己圖片寬度的3倍
Animation scale = new ScaleAnimation(0, 0.3f, 0, 0.5f,
ScaleAnimation.RELATIVE_TO_SELF, 3f,
ScaleAnimation.RELATIVE_TO_SELF, 3f);
scale.setDuration(3000);
scale.setFillAfter(true);
iv.startAnimation(scale);

安卓動畫基礎講解

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.