国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android編程中Tween動畫和Frame動畫實例分析

2020-04-11 11:05:44
字體:
來源:轉載
供稿:網友

本文實例講述了Android編程中Tween動畫和Frame動畫實現方法。分享給大家供大家參考,具體如下:

Animation主要有兩種動畫模式:Tween動畫和Frame動畫

Tween動畫由四種類型組成

alpha
漸變透明度動畫效果
scale
漸變尺寸伸縮動畫效果
translate
畫面轉換位置移動動畫效果
rotate
畫面轉移旋轉動畫效果

res目錄下新建anim創建Tween.xml

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 透明 --> <alpha android:fromAlpha="1" android:toAlpha="0" android:duration="3000" /> <!-- 旋轉 --> <rotate android:fromDegrees="0" android:toDegrees="360" android:pivotX="50%" android:pivotY="50%" android:duration="3000" /> <!-- 縮放 --> <scale android:fromXScale="1" android:fromYScale="1" android:toXScale="3" android:toYScale="3" android:pivotX="0" android:pivotY="0" android:duration="3000" /> <!-- 移動 --> <translate android:fromXDelta="0" android:fromYDelta="0" android:toXDelta="50%p" android:toYDelta="50%p" android:duration="3000" /></set>

以上每個動畫效果可放在不同的xml文件中已方便查看效果

下邊是Activity中調用動畫

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); imageView = (ImageView) findViewById(R.id.img);}public void onClick(View view) { Animation animation = null; switch (view.getId()) { case R.id.alpha:  animation = AnimationUtils.loadAnimation(this, R.anim.alpha);  break; case R.id.scale:  animation = AnimationUtils.loadAnimation(this, R.anim.scale);  break; case R.id.translate:  animation = AnimationUtils.loadAnimation(this, R.anim.translate);  break; case R.id.rotate:  //animation = AnimationUtils.loadAnimation(this, R.anim.rotate);  //令一種方式JavaCode中 創建RotateAnimation  animation = new RotateAnimation(0, 180, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);  animation.setDuration(3000);  break; case R.id.all:  animation = AnimationUtils.loadAnimation(this, R.anim.Tween);  break; } //啟動動畫 imageView.startAnimation(animation);}

Tween動畫由四種類型組成

幀動畫是有多張圖片組成,多張圖片循環。

示例:

Frame.xml

<?xml version="1.0" encoding="utf-8"?><animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false"> <item android:drawable="@drawable/p1" android:duration="200" /> <item android:drawable="@drawable/p2" android:duration="200" /> <item android:drawable="@drawable/p3" android:duration="200" /> <item android:drawable="@drawable/p4" android:duration="200" /> <item android:drawable="@drawable/p5" android:duration="200" /> <item android:drawable="@drawable/p6" android:duration="200" /> <item android:drawable="@drawable/p7" android:duration="800" /> <item android:drawable="@drawable/p8" android:duration="200" /> <item android:drawable="@drawable/p9" android:duration="200" /> <item android:drawable="@drawable/p10" android:duration="200" /> <item android:drawable="@drawable/p11" android:duration="200" /></animation-list>

main.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@anim/frame" android:onClick="go" /></LinearLayout>

Activity:

public void go(View view) { // 獲取ImageView ImageView imageView = (ImageView) view; // 獲取ImageView上面的動畫圖片 AnimationDrawable drawable = (AnimationDrawable) imageView.getDrawable(); // 動畫開始 drawable.start();}

希望本文所述對大家Android程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 湟中县| 常州市| 时尚| 通河县| 辽宁省| 日喀则市| 萝北县| 云阳县| 东港市| 福建省| 巴青县| 家居| 梅河口市| 潞城市| 紫阳县| 甘德县| 富平县| 外汇| 巴中市| 上杭县| 庆城县| 靖西县| 佳木斯市| 辉南县| 淮北市| 麦盖提县| 峡江县| 宝兴县| 叙永县| 辉县市| 邓州市| 乐安县| 白沙| 牟定县| 旌德县| 滦南县| 遂川县| 九龙城区| 忻州市| 古田县| 蓬莱市|