最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android 動畫之TranslateAnimation應(yīng)用詳解

 更新時間:2012年12月02日 16:15:20   作者:  
本節(jié)講解TranslateAnimation動畫,TranslateAnimation比較常用,比如QQ,網(wǎng)易新聞菜單條的動畫,就可以用TranslateAnimation實現(xiàn),本文將詳細(xì)介紹通過TranslateAnimation 來定義動畫,需要的朋友可以參考下
android中提供了4中動畫:
AlphaAnimation 透明度動畫效果
ScaleAnimation 縮放動畫效果
TranslateAnimation 位移動畫效果
RotateAnimation 旋轉(zhuǎn)動畫效果

本節(jié)講解TranslateAnimation動畫,TranslateAnimation比較常用,比如QQ,網(wǎng)易新聞菜單條的動畫,就可以用TranslateAnimation實現(xiàn),
通過TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta) 來定義動畫

參數(shù)說明:
復(fù)制代碼 代碼如下:

float fromXDelta 動畫開始的點離當(dāng)前View X坐標(biāo)上的差值
float toXDelta 動畫結(jié)束的點離當(dāng)前View X坐標(biāo)上的差值
float fromYDelta 動畫開始的點離當(dāng)前View Y坐標(biāo)上的差值
float toYDelta 動畫開始的點離當(dāng)前View Y坐標(biāo)上的差值

常用方法:
復(fù)制代碼 代碼如下:

animation.setDuration(long durationMillis);//設(shè)置動畫持續(xù)時間
animation.setRepeatCount(int i);//設(shè)置重復(fù)次數(shù)
animation.setRepeatMode(Animation.REVERSE);//設(shè)置反方向執(zhí)行

Xml屬性:
復(fù)制代碼 代碼如下:

android:duration:運行動畫的時間
android:repeatCount:定義動畫重復(fù)的時間

代碼:
復(fù)制代碼 代碼如下:

public class MainActivity extends Activity {
ImageView image;
Button start;
Button cancel;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image = (ImageView) findViewById(R.id.main_img);
start = (Button) findViewById(R.id.main_start);
cancel = (Button) findViewById(R.id.main_cancel);
/** 設(shè)置位移動畫 向右位移150 */
final TranslateAnimation animation = new TranslateAnimation(0, 150,0, 0);
animation.setDuration(2000);//設(shè)置動畫持續(xù)時間
animation.setRepeatCount(2);//設(shè)置重復(fù)次數(shù)
animation.setRepeatMode(Animation.REVERSE);//設(shè)置反方向執(zhí)行
start.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
image.setAnimation(animation);
/** 開始動畫 */
animation.startNow();
}
});
cancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
/** 結(jié)束動畫 */
animation.cancel();
}
});
}
}

效果:

相關(guān)文章

最新評論

柘城县| 黄浦区| 望奎县| 湄潭县| 平罗县| 城步| 左贡县| 托克逊县| 饶平县| 莎车县| 萨嘎县| 永平县| 基隆市| 琼海市| 府谷县| 磴口县| 富川| 九寨沟县| 西乡县| 时尚| 饶阳县| 赤城县| 陕西省| 葫芦岛市| 虎林市| 武威市| 西林县| 都昌县| 新闻| 武陟县| 台北县| 平远县| 修文县| 营口市| 晴隆县| 获嘉县| 临沧市| 北碚区| 达日县| 南昌县| 贵港市|