1.Android動(dòng)畫模式:
創(chuàng)新互聯(lián)公司是一家集網(wǎng)站建設(shè),海滄企業(yè)網(wǎng)站建設(shè),海滄品牌網(wǎng)站建設(shè),網(wǎng)站定制,海滄網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷,網(wǎng)絡(luò)優(yōu)化,海滄網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。1>tweened animation: 漸變動(dòng)畫;
2>frame by frame: 畫面轉(zhuǎn)換動(dòng)畫.
2.Android的Animation動(dòng)畫由四種類型組成:
XML | |
alpha | 漸變透明度動(dòng)畫效果 |
scale | 漸變尺寸伸縮動(dòng)畫效果 |
translate | 畫面轉(zhuǎn)換位置移動(dòng)動(dòng)畫效果 |
rotate | 畫面轉(zhuǎn)移旋轉(zhuǎn)動(dòng)畫效果 |
Java代碼 | |
AlphaAnimation | 漸變透明度動(dòng)畫效果 |
ScaleAnimation | 漸變尺寸伸縮動(dòng)畫效果 |
TranslateAnimation | 畫面轉(zhuǎn)換位置移動(dòng)動(dòng)畫效果 |
RotateAnimation | 畫面轉(zhuǎn)移旋轉(zhuǎn)動(dòng)畫效果 |
3.動(dòng)畫效果示例
在res/下新建anim文件夾,下面動(dòng)畫文件放入anim下面
1> alpha 淡入效果:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="2000" /> </set> <!-- fromAlpha:開始時(shí)透明度 toAlpha: 結(jié)束時(shí)透明度 duration:動(dòng)畫持續(xù)時(shí)間 -->
2>alpha 淡出效果:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="2000" /> </set> <!-- fromAlpha:開始時(shí)透明度 toAlpha: 結(jié)束時(shí)透明度 duration:動(dòng)畫持續(xù)時(shí)間 -->
3> rotate 旋轉(zhuǎn)效果:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="false" android:zAdjustment="bottom" > <rotate android:duration="4000" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:toDegrees="360" /> <!-- fromDegrees 動(dòng)畫開始時(shí)的角度 toDegrees 動(dòng)畫結(jié)束時(shí)物件的旋轉(zhuǎn)角度,正代表順時(shí)針 pivotX 屬性為動(dòng)畫相對(duì)于物件的X坐標(biāo)的開始位置 pivotY 屬性為動(dòng)畫相對(duì)于物件的Y坐標(biāo)的開始位置 --> </set>
4> scale 縮放效果:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <scale android:duration="10000" android:fromXScale="0.0" android:fromYScale="0.0" android:interpolator="@android:anim/decelerate_interpolator" android:pivotX="50%" android:pivotY="50%" android:repeatCount="1" android:repeatMode="reverse" android:startOffset="0" android:toXScale="1.5" android:toYScale="1.5" /> </set> <!-- fromXDelta,fromYDelta 起始時(shí)X,Y座標(biāo),屏幕右下角的座標(biāo)是X:320,Y:480 toXDelta, toYDelta 動(dòng)畫結(jié)束時(shí)X,Y的座標(biāo) --> <!-- interpolator 指定動(dòng)畫插入器 常見(jiàn)的有加速減速插入器 accelerate_decelerate_interpolator 加速插入器 accelerate_interpolator, 減速插入器 decelerate_interpolator。 fromXScale,fromYScale, 動(dòng)畫開始前X,Y的縮放,0.0為不顯示, 1.0為正常大小 toXScale,toYScale, 動(dòng)畫最終縮放的倍數(shù), 1.0為正常大小,大于1.0放大 pivotX, pivotY 動(dòng)畫起始位置,相對(duì)于屏幕的百分比,兩個(gè)都為50%表示動(dòng)畫從屏幕中間開始 startOffset, 動(dòng)畫多次執(zhí)行的間隔時(shí)間,如果只執(zhí)行一次,執(zhí)行前會(huì)暫停這段時(shí)間, 單位毫秒 duration,一次動(dòng)畫效果消耗的時(shí)間,單位毫秒, 值越小動(dòng)畫速度越快 repeatCount,動(dòng)畫重復(fù)的計(jì)數(shù),動(dòng)畫將會(huì)執(zhí)行該值+1次 repeatMode,動(dòng)畫重復(fù)的模式,reverse為反向,當(dāng)?shù)谂即螆?zhí)行時(shí),動(dòng)畫方向會(huì)相反。 restart為重新執(zhí)行,方向不變 -->
5> translate 移動(dòng)效果:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="4000" android:fromXDelta="0" android:fromYDelta="0" android:toXDelta="50" android:toYDelta="0" /> </set> <!-- fromXDelta,fromYDelta 起始時(shí)X,Y座標(biāo),屏幕右下角的座標(biāo)是X:320,Y:480 toXDelta, toYDelta 動(dòng)畫結(jié)束時(shí)X,Y的座標(biāo) -->
在代碼中引用動(dòng)畫文件:
public class MainActivity extends Activity implements android.view.View.OnClickListener { private TextView tvShow; private Button btnRotate,btnFadeOut,btnFadeIn,btnScale,btnTranslate; private Animation animation = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); tvShow = (TextView) findViewById(R.id.tvShow); btnRotate = (Button) findViewById(R.id.btnRotate); btnRotate.setOnClickListener(this); btnFadeOut = (Button) findViewById(R.id.btnFadeOut); btnFadeOut.setOnClickListener(this); btnFadeIn = (Button) findViewById(R.id.btnFadeIn); btnFadeIn.setOnClickListener(this); btnScale = (Button) findViewById(R.id.btnScale); btnScale.setOnClickListener(this); btnTranslate = (Button) findViewById(R.id.btnTranslate); btnTranslate.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { //翻轉(zhuǎn) case R.id.btnRotate: animation = AnimationUtils.loadAnimation(this, R.anim.rotate); break; //淡出 case R.id.btnFadeOut: animation = AnimationUtils.loadAnimation(this, R.anim.alpha_fadeout); break; //淡入 case R.id.btnFadeIn: animation = AnimationUtils.loadAnimation(this, R.anim.alpha_fadein); break; //縮放 case R.id.btnScale: animation = AnimationUtils.loadAnimation(this, R.anim.scale); break; //平移 case R.id.btnTranslate: animation = AnimationUtils.loadAnimation(this, R.anim.translate); break; default: break; } if(animation != null){ tvShow.startAnimation(animation); } } }
效果見(jiàn)下圖:
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
分享題目:Android學(xué)習(xí)——Animation動(dòng)畫效果-創(chuàng)新互聯(lián)
分享鏈接:http://www.rwnh.cn/article6/cejgog.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、企業(yè)建站、App開發(fā)、云服務(wù)器、電子商務(wù)、定制開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容