android學習(屬性動畫扇形功能表列)

來源:互聯網
上載者:User

標籤:

  1 public class TestActivity extends Activity implements OnClickListener{  2     private int[] res={R.id.imageView1,R.id.imageView2,R.id.imageView3,R.id.imageView4,R.id.imageView5,R.id.imageView6};  3     private List<ImageView> list=new ArrayList<ImageView>();  4     private boolean flag;  5     @Override  6     protected void onCreate(Bundle savedInstanceState) {  7         // TODO Auto-generated method stub  8         super.onCreate(savedInstanceState);  9         setContentView(R.layout.tests); 10         for(int i=0;i<res.length;i++){ 11             ImageView iv=(ImageView) findViewById(res[i]); 12             iv.setOnClickListener(this); 13             list.add(iv); 14         } 15          16     } 17 /** 18 public void move(View view){ 19     ImageView iv=(ImageView) findViewById(R.id.imageView1); 20     //屬性動畫 21 //    ObjectAnimator.ofFloat(iv, "translationX", 0,200f).setDuration(1000).start();//X軸移動  22      23     //第2種 最佳化 24 //    PropertyValuesHolder p1=PropertyValuesHolder.ofFloat("translationX", 0,200f); 25 //    PropertyValuesHolder p2=PropertyValuesHolder.ofFloat("translationY", 0,200f); 26 //    PropertyValuesHolder p3=PropertyValuesHolder.ofFloat("rotation", 0,360f); 27 //    ObjectAnimator.ofPropertyValuesHolder(iv, p1,p2,p3).setDuration(1000).start(); 28      29     //結合  30     AnimatorSet set=new AnimatorSet(); 31     ObjectAnimator oa1=ObjectAnimator.ofFloat(iv, "translationX", 0,200f); 32     ObjectAnimator oa2=ObjectAnimator.ofFloat(iv, "translationY", 0,200f); 33     ObjectAnimator oa3=ObjectAnimator.ofFloat(iv, "rotation", 0,360f); 34 //    set.playTogether(oa1,oa2,oa3);//一起 35 //    set.playSequentially(oa1,oa2,oa3);//順序播放 36     set.play(oa1).with(oa2); 37     set.play(oa3).after(oa2);//平移在一起,最後在旋轉 38     set.setDuration(1000); 39     set.start(); 40 } 41 */ 42  43     @Override 44     public void onClick(View v) { 45         switch (v.getId()) { 46         case R.id.imageView1: 47             if(flag){ 48             startAnimat(); 49             }else{ 50                 closeAnimat(); 51             } 52             break; 53  54         default: 55             Toast.makeText(this, "click"+v.getId(), Toast.LENGTH_SHORT).show(); 56             break; 57         } 58          59     } 60 private void closeAnimat() { 61     for(int i=1;i<res.length;i++){ 62         AnimatorSet set=new AnimatorSet(); 63         ObjectAnimator oa1=ObjectAnimator.ofFloat(list.get(i), "translationX",(float)Math.sin(Math.toRadians((i-1)*90/(5-1)))*200 ,0); 64         ObjectAnimator oa2=ObjectAnimator.ofFloat(list.get(i), "translationY",(float)Math.cos(Math.toRadians((i-1)*90/(5-1)))*200 ,0); 65         set.playTogether(oa1,oa2); 66         set.setDuration(3000); 67         set.setInterpolator(new BounceInterpolator()); 68 //        set.setStartDelay(i*300); 69         set.start(); 70         flag=true; 71          72     } 73      74 } 75 /** 76  * 菜單展開 77  */ 78 private void startAnimat() { 79     // TODO Auto-generated method stub 80     for(int i=1;i<res.length;i++){ 81         AnimatorSet set=new AnimatorSet(); 82         ObjectAnimator oa1=ObjectAnimator.ofFloat(list.get(i), "translationX",0,(float)Math.sin(Math.toRadians((i-1)*90/(5-1)))*200 ); 83         ObjectAnimator oa2=ObjectAnimator.ofFloat(list.get(i), "translationY",0,(float)Math.cos(Math.toRadians((i-1)*90/(5-1)))*200 ); 84         set.playTogether(oa1,oa2); 85         set.setDuration(3000); 86 //        set.setStartDelay(i*300); 87         set.start(); 88         flag=false; 89          90     } 91 } 92      93     /** 94      * 監聽事件 95      */ 96 //    public void move(View view){ 97 //        ObjectAnimator oa1=ObjectAnimator.ofFloat(view, "alpha", 0,1f); 98 //        oa1.setDuration(1000).start(); 99 //        oa1.addListener(new AnimatorListenerAdapter() {100 //            @Override101 //            public void onAnimationEnd(Animator animation) {102 //                Toast.makeText(TestActivity.this,"click", Toast.LENGTH_SHORT).show();103 //            }104 //        });105 //    }106 }

布局檔案

 1 <?xml version="1.0" encoding="utf-8"?> 2 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 3     android:layout_width="match_parent" 4     android:layout_height="match_parent" > 5  6      7  8     <ImageView 9         android:id="@+id/imageView3"10         android:paddingLeft="5dp"11         android:paddingTop="5dp"12         android:layout_width="wrap_content"13         android:layout_height="wrap_content"14         android:src="@drawable/c" />15 16     <ImageView17         android:id="@+id/imageView4"18         android:layout_width="wrap_content"19         android:layout_height="wrap_content"20         android:paddingLeft="5dp"21         android:paddingTop="5dp"22         android:src="@drawable/d" />23 24     <ImageView25         android:id="@+id/imageView5"26         android:paddingLeft="5dp"27         android:paddingTop="5dp"28         android:layout_width="wrap_content"29         android:layout_height="wrap_content"30         android:src="@drawable/e" />31 32     <ImageView33         android:id="@+id/imageView6"34         android:layout_width="wrap_content"35         android:layout_height="wrap_content"36         android:paddingLeft="5dp"37         android:paddingTop="5dp"38         android:src="@drawable/f" />39 40     41 42     <ImageView43         android:id="@+id/imageView2"44         android:layout_width="wrap_content"45         android:layout_height="wrap_content"46         android:paddingLeft="5dp"47         android:paddingTop="5dp"48         android:src="@drawable/b" />49 <ImageView50         android:id="@+id/imageView1"51         android:layout_width="wrap_content"52         android:layout_height="wrap_content"53         android:src="@drawable/a" />54 </FrameLayout>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

mark

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.