国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android Animation之TranslateAnimation(平移動畫)

2019-10-22 18:27:02
字體:
來源:轉載
供稿:網友

TranslateAnimation(平移動畫)的意思無非就是一張圖片或其他從一個位置到達另外一個位置。直接代碼分析,相關重要屬性參數解釋都在代碼中。

1、首先編寫main.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:paddingLeft="@dimen/activity_horizontal_margin"   android:paddingRight="@dimen/activity_horizontal_margin"   android:paddingTop="@dimen/activity_vertical_margin"   android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">   <ImageView     android:id="@+id/image"     android:text="@string/hello_world"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:src="@drawable/car_one1"/> </RelativeLayout> 

2、接下來編寫MainActivity.java文件。

package com.example.dell.bitmapproject; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.view.animation.Animation; import android.view.animation.AnimationSet; import android.view.animation.TranslateAnimation; import android.widget.ImageView; public class MainActivity extends AppCompatActivity {   private ImageView image;   @Override   protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.main);     image =(ImageView)findViewById(R.id.image);     image.setOnClickListener(new OnClickListenerImpl());   }   private class OnClickListenerImpl implements View.OnClickListener {     @Override     public void onClick(View v) {       /*         AnimationSet相當于一個動畫的集合,true表示使用Animation的interpolator         false則是使用自己的。         Interpolator 被用來修飾動畫效果,定義動畫的變化率,可以使存在的動畫效果         accelerated(加速),decelerated(減速),repeated(重復),bounced(彈跳)等。        */       AnimationSet animationSet = new AnimationSet(true);       /*           Animation還有幾個方法           setFillAfter(boolean fillAfter)           如果fillAfter的值為真的話,動畫結束后,控件停留在執行后的狀態           setFillBefore(boolean fillBefore)           如果fillBefore的值為真的話,動畫結束后,控件停留在動畫開始的狀態           setStartOffset(long startOffset)           設置動畫控件執行動畫之前等待的時間           setRepeatCount(int repeatCount)           設置動畫重復執行的次數        */       TranslateAnimation translateAnimation = new TranslateAnimation(           //X軸初始位置           Animation.RELATIVE_TO_SELF, 0.0f,           //X軸移動的結束位置           Animation.RELATIVE_TO_SELF,0.5f,           //y軸開始位置           Animation.RELATIVE_TO_SELF,0.0f,           //y軸移動后的結束位置           Animation.RELATIVE_TO_SELF,1.5f);       //3秒完成動畫       translateAnimation.setDuration(2000);       //如果fillAfter的值為真的話,動畫結束后,控件停留在執行后的狀態       animationSet.setFillAfter(true);       //將AlphaAnimation這個已經設置好的動畫添加到 AnimationSet中       animationSet.addAnimation(translateAnimation);       //啟動動畫       MainActivity.this.image.startAnimation(animationSet);     }   } } 

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 佛山市| 扎囊县| 阿鲁科尔沁旗| 瓦房店市| 黔江区| 湾仔区| 来凤县| 额敏县| 嫩江县| 汪清县| 仙居县| 广昌县| 瑞丽市| 清新县| 阳信县| 逊克县| 都匀市| 桐庐县| 平遥县| 临沂市| 普陀区| 北碚区| 长垣县| 西安市| 图们市| 定襄县| 汕头市| 江达县| 化州市| 洱源县| 长宁区| 阿克| 河东区| 余江县| 五台县| 扎囊县| 博爱县| 海口市| 张掖市| 海林市| 任丘市|