a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 系統 > Android > 正文

Android屬性動畫特點詳解

2019-10-21 21:35:21
字體:
來源:轉載
供稿:網友

本文實例為大家分享了Android屬性動畫使用的具體代碼,供大家參考,具體內容如下

MainActivity.java

/*屬性動畫的特點:動畫效果會改變控件的位置.且開啟動畫的是動畫對象,而不是控件對象.    只有旋轉的屬性動畫是經常用的,注意參數.    注意:這些方法都是安卓在3.0以后出現的新特性,所以要把AndroidManifest.xml里的android:minSdkVersion值修改為11以上*///注釋后面有222的暫時不用管.public class MainActivity extends AppCompatActivity implements View.OnClickListener {  private ImageButton imageView;  private Button alpha_bt;  private Button rotationY_bt;  private Button scaleX_bt;  private Button translationX_bt;  private Button AnimatorSet_bt;  @Override  protected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_main);//    對控件進行初始化    init();//   此處用的是xml的形式.引用在Xml里的屬性動畫資源. AnimatorInflater.loadAnimator(上下文,R.animator..)222    Animator Xmlanimator = AnimatorInflater.loadAnimator(this, R.animator.objectanimator);//   把要做動畫控件對象放進去.Animator.setTarget(View對象);222    Xmlanimator.setTarget(imageView);//   開啟動畫.Animator.start.222    Xmlanimator.start();  }  // 對于控件進行初始化  private void init() {    //找到ImageView控件對象    imageView = (ImageButton) findViewById(R.id.animation_iv);    //找到Button控件對象.    alpha_bt = (Button) findViewById(R.id.alpha_bt);    rotationY_bt = (Button) findViewById(R.id.rotationY_bt);    scaleX_bt = (Button) findViewById(R.id.scaleX_bt);    translationX_bt = (Button) findViewById(R.id.translationY_bt);    AnimatorSet_bt = (Button) findViewById(R.id.AnimatorSet_bt);    //為button設置點擊事件    alpha_bt.setOnClickListener(this);    rotationY_bt.setOnClickListener(this);    scaleX_bt.setOnClickListener(this);    translationX_bt.setOnClickListener(this);    AnimatorSet_bt.setOnClickListener(this);  }  /**   * 根據點擊事件類型.調用控件做屬性動畫的   *   * @param view   */  @Override  public void onClick(View view) {    switch (view.getId()) {      case R.id.alpha_bt:        //做透明動畫,參數1:View,代表你要修改那個控件的屬性. 參數2:propertyName代表實現什么樣子的動畫:"alpha",String類型.        //參數3:float... values,控件修改的參數,new float[]{0.0f, 0.2f, 0.4f, 0.6f, 0.8f, 1.0f}        ObjectAnimator alpha = ObjectAnimator.ofFloat(imageView, "alpha", new float[]{0.0f, 0.2f, 0.4f, 0.6f, 0.8f, 1.0f});        //設置動畫執行時長.setDuration        alpha.setDuration(2000);        //設置動畫執行的模式setRepeatMode,參數用ObjectAnimator引用.        alpha.setRepeatMode(ObjectAnimator.RESTART);        //設置動畫執行的次數.setRepeatCount        alpha.setRepeatCount(1);        //使用ObjectAnimator對象開啟動畫.        alpha.start();        break;      case R.id.rotationY_bt:        //做旋轉動畫,"rotationY".rotationX,rotation new float[]{90f, 180f, 270f, 360f}        ObjectAnimator rotationY = ObjectAnimator.ofFloat(imageView, "rotationY", new float[]{90f, 180f, 270f, 360f});        rotationY.setDuration(2000);        rotationY.setRepeatMode(ObjectAnimator.RESTART);        rotationY.setRepeatCount(1);        rotationY.start();        break;      case R.id.scaleX_bt:        //做縮放動畫,scaleX,scaleY new float[]{1f, 2f, 3f, 4f, 5f, 6f,1f}        ObjectAnimator scaleX = ObjectAnimator.ofFloat(imageView, "scaleX", new float[]{1f, 2f, 3f, 4f, 5f, 6f, 1f});        scaleX.setDuration(2000);        scaleX.setRepeatMode(ObjectAnimator.RESTART);        scaleX.setRepeatCount(1);        scaleX.start();        break;      case R.id.translationY_bt:        //做平移動畫,translationY,translationX new float[]{10f, 20f, 30f, 40f, 60f, 80f}        ObjectAnimator translationY = ObjectAnimator.ofFloat(imageView, "translationY", new float[]{10f, 20f, 30f, 40f, 60f, 80f});        translationY.setDuration(2000);        translationY.setRepeatMode(ObjectAnimator.RESTART);        translationY.setRepeatCount(1);        translationY.start();        //做動畫集合AnimatorSet,分別創建兩個動畫對象.注意playTogether(動畫對象...)和playSequentially的區別.最后開啟動畫.start      case R.id.AnimatorSet_bt:        AnimatorSet set = new AnimatorSet();        ObjectAnimator oa = ObjectAnimator.ofFloat(imageView, "translationX", new float[]{10f, 20f, 30f, 40f, 60f, 80f});        oa.setDuration(3000);        ObjectAnimator oa2 = ObjectAnimator.ofFloat(imageView, "translationY", new float[]{-10f, -20f, -30f, -40f, -60f, -80f});        oa2.setDuration(3000);        set.playTogether(oa, oa2);        set.start();        break;      default:        break;    }  }}

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical"><!--  注意background的屬性置為null -->  <Button    android:id="@+id/alpha_bt"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="alpha"/>  <Button    android:id="@+id/translationY_bt"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="translationY"/>  <Button    android:id="@+id/scaleX_bt"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="scaleX"/>  <Button    android:id="@+id/rotationY_bt"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="rotationY"/>  <Button    android:id="@+id/AnimatorSet_bt"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="AnimatorSet"/>  <ImageButton    android:onClick="yyyy"    android:id="@+id/animation_iv"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_gravity="center"    android:src="@drawable/a8"    android:background="@null"/></LinearLayout>


在res目錄下創建animator文件夾在文件夾里創建以下xml

objectanimator.xml

<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"  android:propertyName="rotationX"  android:duration="3000"  android:repeatCount="1"  android:repeatMode="reverse"  android:startOffset="0"  android:valueFrom="360.0"></objectAnimator><!--注意:在xml定義動畫類的屬性,浮點型小數,直接寫小數即可,不用再帶f.提示:控件位移的參照單位在xml文件里有所不同,不過更簡單,不用再特意去定義參照物屬性了,直接是根據值,區分兩種方式:  一種是以整個屏幕為參照物,在xml文件屬性定義值是int%p;  一種以控件自身大小為參照物,在xml文件屬性定義值是int-->

--------------------- 
作者:FanRQ_ 
來源:CSDN 
原文:https://blog.csdn.net/FanRQ_/article/details/84072052 
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 成人黄色免费网站 | 国产极品一区二区 | 视频一区二区三区在线观看 | 在线 丝袜 欧美 日韩 制服 | 欧美大片免费高清观看 | 久草在线资源福利站 | 韩国精品 | 91精品国产综合久久久蜜臀粉嫩 | 免费观看特级毛片 | 欧美成人精品一区二区男人看 | 婷婷色在线 | 亚洲成人在线视频播放 | av免费观看在线 | 国产精品兄妹在线观看麻豆 | 亚洲欧美一区二区三区国产精品 | 日韩三级电影在线免费观看 | 草逼网站 | 亚洲精品在线国产 | 精品国产色 | 日韩免费一区二区三区 | 做a视频 | 日本视频免费高清一本18 | 国产精品一区av | 国产精品视频一区二区三区四蜜臂 | 国内精品一区二区 | 国产一区二区视频在线 | 中国一级大黄大黄大色毛片 | 欧美在线视频一区二区 | 国产精品99久久免费观看 | 国产精品乱码一区二区三区 | 欧美精品a∨在线观看不卡 国产精品一区二区三区在线 | 国产xxxxxxxxxx | 欧美 日韩 中文字幕 | 欧美自拍一区 | 日韩中文字幕视频在线观看 | 一级毛片在线看aaaa | 日韩 欧美 自拍 | 国产精品二区一区二区aⅴ污介绍 | 亚洲激情在线观看 | 亚洲免费视频一区二区 | 日本亚洲欧美 |