一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語(yǔ)言|JavaScript|易語(yǔ)言|vb.net|

服務(wù)器之家 - 編程語(yǔ)言 - Android - Android補(bǔ)間動(dòng)畫(huà)基本使用(位移、縮放、旋轉(zhuǎn)、透明)

Android補(bǔ)間動(dòng)畫(huà)基本使用(位移、縮放、旋轉(zhuǎn)、透明)

2022-02-20 15:23yu-Sniper Android

這篇文章主要介紹了Android補(bǔ)間動(dòng)畫(huà)基本使用(位移、縮放、旋轉(zhuǎn)、透明),補(bǔ)間動(dòng)畫(huà)就是原形態(tài)變成新形態(tài)時(shí)為了過(guò)渡變形過(guò)程,生成的動(dòng)畫(huà)

本文講述了Android補(bǔ)間動(dòng)畫(huà)基本使用(位移、縮放、旋轉(zhuǎn)、透明)。分享給大家供大家參考,具體如下:

補(bǔ)間動(dòng)畫(huà)

原形態(tài)變成新形態(tài)時(shí)為了過(guò)渡變形過(guò)程,生成的動(dòng)畫(huà)就叫補(bǔ)間動(dòng)畫(huà)
位移、旋轉(zhuǎn)、縮放、透明

位移:

參數(shù)10指的是X的起點(diǎn)坐標(biāo),但不是指屏幕x坐標(biāo)為10的位置,而是imageview的 真實(shí)X + 10
參數(shù)150指的是X的終點(diǎn)坐標(biāo),它的值是imageview的 真實(shí)X + 150

//創(chuàng)建為位移動(dòng)畫(huà)對(duì)象,設(shè)置動(dòng)畫(huà)的初始位置和結(jié)束位置

TranslateAnimation ta = new TranslateAnimation(10, 150, 20, 140);

1.  x坐標(biāo)的起點(diǎn)位置,如果相對(duì)于自己,傳0.5f,那么起點(diǎn)坐標(biāo)就是 真實(shí)X + 0.5 * iv寬度;

2.  x坐標(biāo)的終點(diǎn)位置,如果傳入2,那么終點(diǎn)坐標(biāo)就是 真實(shí)X + 2 * iv的寬度;

3.  y坐標(biāo)的起點(diǎn)位置,如果傳入0.5f,那么起點(diǎn)坐標(biāo)就是 真實(shí)Y + 0.5 * iv高度;

4.  y坐標(biāo)的終點(diǎn)位置,如果傳入2,那么終點(diǎn)坐標(biāo)就是 真實(shí)Y + 2 * iv高度。

 TranslateAnimation ta = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 2, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 2);

動(dòng)畫(huà)播放相關(guān)的設(shè)置

?
1
2
3
4
5
6
7
8
9
10
//設(shè)置動(dòng)畫(huà)持續(xù)時(shí)間
ta.setDuration(2000);
 //動(dòng)畫(huà)重復(fù)播放的次數(shù)
ta.setRepeatCount(1);
 //動(dòng)畫(huà)重復(fù)播放的模式
ta.setRepeatMode(Animation.REVERSE);
 //動(dòng)畫(huà)播放完畢后,組件停留在動(dòng)畫(huà)結(jié)束的位置上
ta.setFillAfter(true);
 //播放動(dòng)畫(huà)
iv.startAnimation(ta);

縮放:

1.參數(shù)0.1f表示動(dòng)畫(huà)的起始寬度是真實(shí)寬度的0.1倍
2.參數(shù)4表示動(dòng)畫(huà)的結(jié)束寬度是真實(shí)寬度的4倍
3.縮放的中心點(diǎn)在iv左上角

ScaleAnimation sa = new ScaleAnimation(0.1f, 4, 0.1f, 4);

1.  參數(shù)0.1f和4意義與上面相同

2.  改變縮放的中心點(diǎn):傳入的兩個(gè)0.5f,類型都是相對(duì)于自己,這兩個(gè)參數(shù)改變了縮放的中心點(diǎn)

3.  中心點(diǎn)x坐標(biāo) = 真實(shí)X + 0.5 * iv寬度

4.  中心點(diǎn)Y坐標(biāo) = 真實(shí)Y + 0.5 * iv高度

 ScaleAnimation sa = new ScaleAnimation(0.1f, 4, 0.1f, 4, Animation.RELATIVETOSELF, 0.5f, Animation.RELATIVETOSELF, 0.5f);

透明:

0為完全透明,1為完全不透明

AlphaAnimation aa = new AlphaAnimation(0, 0.5f);

旋轉(zhuǎn):

1.  20表示動(dòng)畫(huà)開(kāi)始時(shí)的iv的角度

2.  360表示動(dòng)畫(huà)結(jié)束時(shí)iv的角度

3.  默認(rèn)旋轉(zhuǎn)的圓心在iv左上角

RotateAnimation ra = new RotateAnimation(20, 360);

1.  20,360的意義和上面一樣

2.  指定圓心坐標(biāo),相對(duì)于自己,值傳入0.5,那么圓心的x坐標(biāo):真實(shí)X + iv寬度 * 0.5

3.  圓心的Y坐標(biāo):真實(shí)Y + iv高度 * 0.5

RotateAnimation ra = new RotateAnimation(20, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

所有動(dòng)畫(huà)一起飛

?
1
2
3
4
5
6
7
//創(chuàng)建動(dòng)畫(huà)集合
AnimationSet set = new AnimationSet(false);
//往集合中添加動(dòng)畫(huà)
set.addAnimation(aa);
set.addAnimation(sa);
set.addAnimation(ra);
iv.startAnimation(set);

效果如圖:

Android補(bǔ)間動(dòng)畫(huà)基本使用(位移、縮放、旋轉(zhuǎn)、透明)

布局代碼:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context=".MainActivity">
 <ImageView
 android:id="@+id/iv"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:src="@drawable/ic_launcher"
 android:layout_centerVertical="true"
 android:layout_centerHorizontal="true" />
 <LinearLayout
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:gravity="center_horizontal"
 android:layout_alignParentBottom="true"
 android:orientation="horizontal">
 <Button
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:onClick="translate"
 android:text="平移" />
 <Button
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:onClick="scale"
 android:text="縮放" />
 <Button
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:onClick="alpha"
 android:text="透明" />
 <Button
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:onClick="rotate"
 android:text="旋轉(zhuǎn)" />
 <Button
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:onClick="fly"
 android:text="一起飛" />
 </LinearLayout>
</RelativeLayout>

MainActivity.java

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
 public class MainActivity extends Activity {
 private ImageView iv;
 private TranslateAnimation ta;
 private ScaleAnimation sa;
 private AlphaAnimation aa;
 private RotateAnimation ra;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 iv = (ImageView) findViewById(R.id.iv);
 }
 //平移
 public void translate(View view) {
// ta = new TranslateAnimation(10, 100, 20, 200);
 ta = new TranslateAnimation(Animation.RELATIVE_TO_SELF, -1, Animation.RELATIVE_TO_SELF, 2,
 Animation.RELATIVE_TO_SELF, -0.5f, Animation.RELATIVE_TO_SELF, 1.5f);
 //設(shè)置播放時(shí)間
 ta.setDuration(2000);
 //設(shè)置重復(fù)次數(shù)
 ta.setRepeatCount(1);
 //動(dòng)畫(huà)重復(fù)播放的模式
 ta.setRepeatMode(Animation.REVERSE);
 iv.startAnimation(ta);
 }
 //縮放
 public void scale(View view) {
// sa = new ScaleAnimation(2, 4, 2, 4, iv.getWidth() / 2, iv.getHeight() / 2);
 sa = new ScaleAnimation(0.5f, 2, 0.1f, 3, Animation.RELATIVE_TO_SELF, 0.5f,
 Animation.RELATIVE_TO_SELF, 0.5f);
 //設(shè)置播放時(shí)間
 sa.setDuration(2000);
 //設(shè)置重復(fù)次數(shù)
 sa.setRepeatCount(1);
 //動(dòng)畫(huà)重復(fù)播放的模式
 sa.setRepeatMode(Animation.ABSOLUTE);
 //動(dòng)畫(huà)播放完畢后,組件停留在動(dòng)畫(huà)結(jié)束的位置上
 sa.setFillAfter(true);
 iv.startAnimation(sa);
 }
 //透明
 public void alpha(View view) {
 aa = new AlphaAnimation(0, 1);
 //設(shè)置播放時(shí)間
 aa.setDuration(2000);
 //設(shè)置重復(fù)次數(shù)
 aa.setRepeatCount(1);
 //動(dòng)畫(huà)重復(fù)播放的模式
 aa.setRepeatMode(Animation.REVERSE);
 //動(dòng)畫(huà)播放完畢后,組件停留在動(dòng)畫(huà)結(jié)束的位置上
// aa.setFillAfter(true);
 iv.startAnimation(aa);
 }
 //旋轉(zhuǎn)
 public void rotate(View view) {
 ra = new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f,
 Animation.RELATIVE_TO_SELF, 0.5f);
 //設(shè)置播放時(shí)間
 ra.setDuration(2000);
 //設(shè)置重復(fù)次數(shù)
 ra.setRepeatCount(1);
 //動(dòng)畫(huà)重復(fù)播放的模式
 ra.setRepeatMode(Animation.REVERSE);
 //動(dòng)畫(huà)播放完畢后,組件停留在動(dòng)畫(huà)結(jié)束的位置上
 ra.setFillAfter(true);
 iv.startAnimation(ra);
 }
 //位移、縮放、透明、旋轉(zhuǎn)同時(shí)進(jìn)行
 public void fly(View view) {
 AnimationSet set = new AnimationSet(false);
 set.addAnimation(ta);
 set.addAnimation(sa);
 set.addAnimation(aa);
 set.addAnimation(ra);
 iv.startAnimation(set);
 }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

原文鏈接:https://blog.csdn.net/u014657752/article/details/48089939

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 甜蜜调教 | 肉大捧一进一出视频免费播放 | 男生操女生的漫画 | 欧美性色欧美a在线播放 | 91在线老师啪国自产 | 国产一区二区免费不卡在线播放 | 日韩欧美中文字幕出 | 免费观看视频高清在线 | 国产巨大bbbb俄罗斯 | 娇喘嗯嗯 轻点啊视频福利 九九九九在线精品免费视频 | 日本黄色录像视频 | 外女思春台湾三级 | 9966久久精品免费看国产 | 黄瓜视频黄 | 久久成人永久免费播放 | 国产精品女主播自在线拍 | 色欧美在线 | 亚洲成色 | 俄罗斯精品bbw | 狠狠色婷婷丁香六月 | 国产婷婷综合丁香亚洲欧洲 | 青草草在线观看 | 国产一卡二卡3卡4卡更新 | 欧美日韩精品一区二区三区高清视频 | 久久日韩精品无码一区 | 亚洲色图150p | 日本xx高清视频免费观看 | 男人天堂色 | 亚洲天堂色图 | 亚洲国产精品综合福利专区 | 亚洲福利电影一区二区? | 极品丝袜老师h系列全文阅读 | 小苹果日本在线观看 | 深夜免费网站 | 国产18在线| 美女视频一区二区三区在线 | 亚洲人成绝费网站色ww | 动漫美女被羞羞产奶 | 亚洲天堂中文 | 精品亚洲永久免费精品 | 无限好资源免费观看 |