Android?Studio實(shí)現(xiàn)簡(jiǎn)單補(bǔ)間動(dòng)畫(huà)
本文實(shí)例為大家分享了Android Studio實(shí)現(xiàn)簡(jiǎn)單補(bǔ)間動(dòng)畫(huà)的具體代碼,供大家參考,具體內(nèi)容如下
1、動(dòng)畫(huà)發(fā)在res/anim/,創(chuàng)建new/Directory

2、創(chuàng)建動(dòng)畫(huà), 平移,縮放,旋轉(zhuǎn),改變透明度
//平移 <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> ? <translate ? ? ? android:fromXDelta="0.0" ? ? android:fromYDelta="0.0" ? ? android:toXDelta="100" ? ? android:toYDelta="0.0" ? ? android:repeatMode="reverse" ? ? android:repeatCount="infinite" ? ? android:duration="4000" ? ? /> ? </set> //縮放 <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <scale ? ? ? android:repeatMode="reverse" ? ? android:repeatCount="infinite" ? ? android:duration="3000" ? ? android:fromXScale="1.0" ? ? android:fromYScale="1.0" ? ? android:toXScale="0.5" ? ? android:toYScale="0.5" ? ? android:pivotX="50%" ? ? android:pivotY="50%"/> ? </set> //旋轉(zhuǎn) <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> ? ? ? <rotate android:fromDegrees="0" ? ? ? ? android:toDegrees="360" ? ? ? ? android:pivotX="50%" ? ? ? ? android:pivotY="50%" ? ? ? ? android:repeatMode="reverse" ? ? ? ? android:repeatCount="infinite" ? ? ? ? android:duration="1000" ? ? ? ? /> ? </set> //改變透明度 <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha ? ? android:interpolator="@android:anim/linear_interpolator" ? ? android:repeatMode="reverse" ? ? android:repeatCount="infinite" ? ? android:duration="1000" ? ? android:fromAlpha="1.0" ? ? android:toAlpha="0.0"/> ? </set>
3、布局activity_main.xml,點(diǎn)擊按鈕圖片發(fā)送變化,圖片需要自己下載添加44
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" ? ? xmlns:app="http://schemas.android.com/apk/res-auto" ? ? xmlns:tools="http://schemas.android.com/tools" ? ? android:layout_width="match_parent" ? ? android:layout_height="match_parent" ? ? android:layout_weight="1" ? ? android:orientation="vertical" ? ? tools:context=".MainActivity"> ? ? ? ? <ImageView ? ? ? ? ? android:layout_width="300dp" ? ? ? ? ? android:layout_height="300dp" ? ? ? ? ? android:layout_centerInParent="true" ? ? ? ? ? android:layout_gravity="center" ? ? ? ? ? android:id="@+id/fk" ? ? ? ? ? android:src="@drawable/ff"/> ? ? ?<LinearLayout ? ? ? ?android:layout_width="match_parent" ? ? ? ?android:layout_height="match_parent" ? ? ? android:orientation="horizontal"> ? ? ? ? <Button ? ? ? ?android:layout_width="wrap_content" ? ? ? ?android:layout_height="wrap_content" ? ? ? ?android:text="平移" ? ? ? ?android:textSize="24sp" ? ? ? ?android:layout_weight="1" ? ? ? ? android:gravity="center" ? ? ? ? ? android:layout_gravity="bottom" ? ? ? ?android:id="@+id/but"/> ? ? ? <Button ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? android:text="縮放" ? ? ? ? ? android:textSize="24sp" ? ? ? ? ? android:layout_gravity="bottom" ? ? ? ? ? android:layout_weight="1" ? ? ? ? ? android:gravity="center" ? ? ? ? ? android:id="@+id/but1"/> ? ? ? <Button ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? android:text="旋轉(zhuǎn)" ? ? ? ? ? android:textSize="24sp" ? ? ? ? ? android:gravity="center" ? ? ? ? ? android:layout_gravity="bottom" ? ? ? ? ? android:layout_weight="1" ? ? ? ? ? android:id="@+id/but2"/> ? ? ? <Button ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? android:text="改變透明度" ? ? ? ? ? android:textSize="24sp" ? ? ? ? ? android:gravity="center" ? ? ? ? ? android:layout_gravity="bottom" ? ? ? ? ? android:layout_weight="1" ? ? ? ? ? android:id="@+id/but3"/> ? ?</LinearLayout> ? </RelativeLayout>
4、邏輯代碼MainActivity
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
? ? private ImageView imageView;
? ? private Button button;
? ? private Button button1;
? ? private Button button2;
? ? private Button button3;
?
? ? @RequiresApi(api = Build.VERSION_CODES.N)
? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_main);
? ? ? ? //要用控件,定id
? ? ? ? button=findViewById(R.id.but);
? ? ? ? button1=findViewById(R.id.but1);
? ? ? ? button2=findViewById(R.id.but2);
? ? ? ? button3=findViewById(R.id.but3);
?
? ? ? ? imageView=findViewById(R.id.fk);
? ? ? ? button.setOnClickListener(this);
? ? ? ? button1.setOnClickListener(this);
? ? ? ? button2.setOnClickListener(this);
? ? ? ? button3.setOnClickListener(this);
?
? ? }
?
? ? @Override
? ? public void onClick(View view) {
? ? ? ? switch (view.getId()){
? ? ? ? ? ? case R.id.but:
? ? ? ? ? ? ? ? Animation translation= AnimationUtils.loadAnimation(this,R.anim.translate);
? ? ? ? ? ? ? ? imageView.startAnimation(translation);
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? case R.id.but1:
? ? ? ? ? ? ? ? Animation scale= AnimationUtils.loadAnimation(this,R.anim.scale);
? ? ? ? ? ? ? ? imageView.startAnimation(scale);
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? case R.id.but2:
? ? ? ? ? ? ? ? Animation rotate= AnimationUtils.loadAnimation(this,R.anim.rotate);
? ? ? ? ? ? ? ? imageView.startAnimation(rotate);
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? case R.id.but3:
? ? ? ? ? ? ? ? Animation alpha= AnimationUtils.loadAnimation(this,R.anim.alpha);
? ? ? ? ? ? ? ? imageView.startAnimation(alpha);
? ? ? ? ? ? ? ? break;
? ? ? ? }
?
? ? }
}以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android Studio實(shí)現(xiàn)補(bǔ)間動(dòng)畫(huà)
- Android動(dòng)畫(huà)系列之幀動(dòng)畫(huà)和補(bǔ)間動(dòng)畫(huà)的示例代碼
- Android動(dòng)畫(huà)學(xué)習(xí)筆記之補(bǔ)間動(dòng)畫(huà)
- Android補(bǔ)間動(dòng)畫(huà)基本使用(位移、縮放、旋轉(zhuǎn)、透明)
- Android旋轉(zhuǎn)、平移、縮放和透明度漸變的補(bǔ)間動(dòng)畫(huà)
- Android控件Tween動(dòng)畫(huà)(補(bǔ)間動(dòng)畫(huà))實(shí)現(xiàn)方法示例
- android 幀動(dòng)畫(huà),補(bǔ)間動(dòng)畫(huà),屬性動(dòng)畫(huà)的簡(jiǎn)單總結(jié)
- Android幀動(dòng)畫(huà)、補(bǔ)間動(dòng)畫(huà)、屬性動(dòng)畫(huà)用法詳解
- Android動(dòng)畫(huà)之補(bǔ)間動(dòng)畫(huà)(Tween Animation)基礎(chǔ)學(xué)習(xí)
- Android動(dòng)畫(huà)之補(bǔ)間動(dòng)畫(huà)(Tween Animation)實(shí)例詳解
相關(guān)文章
Android簡(jiǎn)易電話(huà)撥號(hào)器實(shí)例詳解
這篇文章主要為大家詳細(xì)介紹了Android簡(jiǎn)易電話(huà)撥號(hào)器實(shí)例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07
Android開(kāi)發(fā)之Location用法實(shí)例分析
這篇文章主要介紹了Android開(kāi)發(fā)中Location用法,結(jié)合實(shí)例形式分析了Android使用location控件獲取經(jīng)緯度信息的相關(guān)操作技巧,需要的朋友可以參考下2016-10-10
Android編程實(shí)現(xiàn)應(yīng)用強(qiáng)制安裝到手機(jī)內(nèi)存的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)應(yīng)用強(qiáng)制安裝到手機(jī)內(nèi)存的方法,涉及Android中屬性設(shè)置的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-11-11
Android?app啟動(dòng)圖適配方法實(shí)例
大家在瀏覽app啟動(dòng)頁(yè)的時(shí)候,一定遇到過(guò)在部分機(jī)型中圖片變形、頁(yè)面不協(xié)調(diào)、文案被裁剪的問(wèn)題,下面這篇文章主要給大家介紹了關(guān)于Android?app啟動(dòng)圖適配的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-01-01
Android 判斷SIM卡屬于哪個(gè)移動(dòng)運(yùn)營(yíng)商詳解及實(shí)例
這篇文章主要介紹了Android 判斷SIM卡屬于哪個(gè)移動(dòng)運(yùn)營(yíng)商詳解相關(guān)資料,并附實(shí)例代碼,具有一定參考價(jià)值,需要的朋友可以參考下2016-11-11
基于Android中手勢(shì)交互的實(shí)現(xiàn)方法
本篇文章是對(duì)Android中手勢(shì)交互的實(shí)現(xiàn)進(jìn)行了詳細(xì)的分析介紹。需要的朋友參考下2013-05-05
Android RadioButton 圖片位置與大小實(shí)例詳解
這篇文章主要介紹了Android RadioButton 圖片位置與大小實(shí)例詳解的相關(guān)資料,這里提供實(shí)例代碼及實(shí)現(xiàn)效果圖,需要的朋友可以參考下2016-11-11
Android自定義ViewGroup之實(shí)現(xiàn)FlowLayout流式布局
這篇文章主要為大家詳細(xì)介紹了Android自定義ViewGroup之實(shí)現(xiàn)FlowLayout流式布局的相關(guān)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-06-06

