android動畫效果示範

來源:互聯網
上載者:User

標籤:

第一種:TranslateAnimation  動畫效果示範: 

public void move(View view){//傳統動畫效果TranslateAnimation animation=new TranslateAnimation(0, 500, 0, 0);//時間animation.setDuration(500);//設定移動後的位置不恢複animation.setFillAfter(true);ImageButton img=(ImageButton) findViewById(R.id.img);TextView tv=(TextView) findViewById(R.id.lab);//設定動畫效果  控制項img.startAnimation(animation);tv.startAnimation(animation);Toast.makeText(this, "移動時間", Toast.LENGTH_SHORT).show();}

 XML 配置按鈕時間

<Button    android:gravity="center"    android:layout_marginTop="500sp"    android:layout_marginStart="30sp"    android:layout_marginLeft="30sp"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="移動按鈕"    android:id="@+id/btn"    android:onClick="move"

 使用-------------使用ObjectAnimator----------360

//  -------------使用ObjectAnimator----------
  ObjectAnimator animator=new ObjectAnimator();
//  animator.ofFloat(img, "translationY", 0,100).setDuration(1000).start();
   if(flag)
  {
  animator.ofFloat(img, "Y", 0,300).setDuration(1000).start();
  animator.ofFloat(img, "X", 0,300).setDuration(1000).start();
  animator.ofFloat(img, "rotation", 0,360).setDuration(1000).start();
  flag=false;
    
  }
  else
  {
  animator.ofFloat(img, "Y", 300,0).setDuration(1000).start();
  animator.ofFloat(img, "X", 300,0).setDuration(1000).start();
  animator.ofFloat(img, "rotation", 3600,0).setDuration(1000).start();
  flag=true;
  }
  

PropertyValuesHolder對象的使用

/** * 跟上面不同的是代碼最佳化了 */public void propteValueHolderDemo(){ImageButton img=(ImageButton) findViewById(R.id.img);PropertyValuesHolder pro1=PropertyValuesHolder.ofFloat("rotation", 0,360F);PropertyValuesHolder pro2=PropertyValuesHolder.ofFloat("x", 0,300);PropertyValuesHolder pro3=PropertyValuesHolder.ofFloat("y", 0,300);ObjectAnimator.ofPropertyValuesHolder(img,pro1,pro2,pro3).setDuration(1000).start();}

 

/** * 按順序 示範動畫效果 */public void PlaySequentiallyDemo(){ImageButton img=(ImageButton) findViewById(R.id.img);ObjectAnimator animator1=ObjectAnimator.ofFloat("img","X",0,360F);ObjectAnimator animator2=ObjectAnimator.ofFloat("img","Y",0,360F);AnimatorSet set=new AnimatorSet();set.playSequentially(animator1,animator2);set.setDuration(1000);set.start();}

 

android動畫效果示範

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.