android AnimationDrawable類實現動畫效果,animationdrawable
布局檔案xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:background="#000000" tools:context=".MainActivity" > <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" /></RelativeLayout>
MainActivity.java
package com.playgif;import android.app.Activity;import android.graphics.drawable.AnimationDrawable;import android.os.Bundle;import android.widget.ImageView;public class MainActivity extends Activity { ImageView imageView = null; AnimationDrawable animation = null;; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imageView = (ImageView)findViewById(R.id.imageView1); imageView.setBackgroundResource(R.drawable.img_list); animation = (AnimationDrawable)imageView.getBackground(); //是否僅啟動一次 animation.setOneShot(false); if(animation.isRunning()) { animation.stop();//停止 } animation.start();//啟動 }}
img_list.xml
<?xml version="1.0" encoding="utf-8"?><animation-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:drawable="@drawable/a1" android:duration="100" /> <item android:drawable="@drawable/a2" android:duration="100" /> <item android:drawable="@drawable/a3" android:duration="100" /> <item android:drawable="@drawable/a4" android:duration="100" /> <item android:drawable="@drawable/a5" android:duration="100" /> <item android:drawable="@drawable/a6" android:duration="100" /> <item android:drawable="@drawable/a7" android:duration="100" /> <item android:drawable="@drawable/a8" android:duration="100" /> <item android:drawable="@drawable/a9" android:duration="100" /> <item android:drawable="@drawable/a10" android:duration="100" /> <item android:drawable="@drawable/a11" android:duration="100" /> <item android:drawable="@drawable/a12" android:duration="100" /> </animation-list>
android:duration指的是延遲, 將要輪詢播放的圖片依次加入list列表。
android 動畫效果 anim的設定我就不說了
imageView.getX()和getY()能得到view所在的位置啊
android 不用XML,怎在代碼裡用animation同時實現圖片的縮放與移動
.....樓上複製帝啊。。。
隨便定義一個AnimationSet as吧(onCreate前,共用)
然後你自己選擇是觸發按鈕還是開始時同時處理啥的~觸發兩個動畫的處理
隨便寫了
suofang();
yidong();
下面定義下。。。。。。
private void suofang()}
as= new AnimationSet(true);//定義一個新AnimationSet
ScaleAnimation sa = new ScaleAnimation(開始x座標伸縮尺寸,開始y座標伸縮尺寸,)
結束x座標伸縮尺寸,結束y座標伸縮尺寸,x軸的百分比,y軸的百分比)//全員float可,
前4個伸縮尺寸0.0伸縮到沒有,1.0正常,大於1.0放大
sa.setDuration(動畫的時間long型);
as.addAnimation(sa);
這個位置寫需要動畫的組件你自己定義的image1,button1什麼的.startAnimation(as);
}
private void yidong(){
as = new Animation(true);
TranslateAnimation ta = new TranslateAnimation(開始x座標,開始y座標,結束x座標,結束y座標);
ta.setDuration();
as.addAnimation(ta);
.startAnimation(as);//跟前面一樣的地方就不寫了。。。比較懶。。。
}