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

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

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

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

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

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

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

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

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

android:duration:運(yùn)行動(dòng)畫的時(shí)間
android:repeatCount:定義動(dòng)畫重復(fù)的時(shí)間

代碼:
復(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è)置位移動(dòng)畫 向右位移150 */
final TranslateAnimation animation = new TranslateAnimation(0, 150,0, 0);
animation.setDuration(2000);//設(shè)置動(dòng)畫持續(xù)時(shí)間
animation.setRepeatCount(2);//設(shè)置重復(fù)次數(shù)
animation.setRepeatMode(Animation.REVERSE);//設(shè)置反方向執(zhí)行
start.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
image.setAnimation(animation);
/** 開始動(dòng)畫 */
animation.startNow();
}
});
cancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
/** 結(jié)束動(dòng)畫 */
animation.cancel();
}
});
}
}

效果:

相關(guān)文章

最新評(píng)論

大厂| 彝良县| 汉源县| 陕西省| 黄陵县| 临海市| 正镶白旗| 乌海市| 新安县| 邵武市| 吉安县| 右玉县| 美姑县| 香格里拉县| 衡山县| 齐齐哈尔市| 靖安县| 库尔勒市| 淮滨县| 无为县| 晴隆县| 庄浪县| 文化| 故城县| 沂南县| 安福县| 德惠市| 永定县| 台东市| 珠海市| 苗栗县| 昌平区| 东台市| 宜兰市| 沙湾县| 都安| 焉耆| 阿鲁科尔沁旗| 康乐县| 揭东县| 微山县|