歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android之幀動畫實現

Android之幀動畫實現

日期:2017/3/1 10:50:44   编辑:Linux編程
今天實現了一個幀動畫的例子,首先在res/anim下建立一個frame.xml來存放幀動畫
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <animation-list xmlns:Android="http://schemas.android.com/apk/res/android" android:oneshot="false">
  3. <item android:drawable="@drawable/girl_1" android:duration="100"/>
  4. <item android:drawable="@drawable/girl_2" android:duration="100"/>
  5. <item android:drawable="@drawable/girl_3" android:duration="100"/>
  6. <item android:drawable="@drawable/girl_4" android:duration="100"/>
  7. <item android:drawable="@drawable/girl_5" android:duration="100"/>
  8. <item android:drawable="@drawable/girl_6" android:duration="100"/>
  9. <item android:drawable="@drawable/girl_7" android:duration="100"/>
  10. <item android:drawable="@drawable/girl_8" android:duration="100"/>
  11. <item android:drawable="@drawable/girl_9" android:duration="100"/>
  12. <item android:drawable="@drawable/girl_10" android:duration="100"/>
  13. <item android:drawable="@drawable/girl_11" android:duration="100"/>
  14. </animation-list>
引用的是drawable下面的圖片,duration是設置時間是100毫秒

看下main.xml的布局

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:orientation="vertical" >
  6. <TextView
  7. android:layout_width="fill_parent"
  8. android:layout_height="wrap_content"
  9. android:text="@string/hello" />
  10. <LinearLayout
  11. android:id="@+id/linearLayout1"
  12. android:layout_width="match_parent"
  13. android:layout_height="wrap_content" >
  14. <Button
  15. android:id="@+id/button1"
  16. android:layout_width="wrap_content"
  17. android:layout_height="wrap_content"
  18. android:text="播放動畫" />
  19. <Button
  20. android:id="@+id/button2"
  21. android:layout_width="wrap_content"
  22. android:layout_height="wrap_content"
  23. android:text="停止動畫" />
  24. </LinearLayout>
  25. <RadioGroup
  26. android:id="@+id/radioGroup1"
  27. android:layout_width="wrap_content"
  28. android:layout_height="wrap_content"
  29. android:orientation="horizontal"
  30. >
  31. <RadioButton
  32. android:id="@+id/radioButton1"
  33. android:layout_width="wrap_content"
  34. android:layout_height="wrap_content"
  35. android:checked="true"
  36. android:text="單次播放" />
  37. <RadioButton
  38. android:id="@+id/radioButton2"
  39. android:layout_width="wrap_content"
  40. android:layout_height="wrap_content"
  41. android:text="循環播放" />
  42. </RadioGroup>
  43. <TextView
  44. android:id="@+id/textView1"
  45. android:layout_width="wrap_content"
  46. android:layout_height="wrap_content"
  47. android:text="拖動進度條修改透明度(0 - 255)之間" />
  48. <SeekBar
  49. android:id="@+id/seekBar1"
  50. android:layout_width="match_parent"
  51. android:layout_height="wrap_content" />
  52. <ImageView
  53. android:id="@+id/imageView1"
  54. android:layout_width="200dip"
  55. android:layout_height="200dip"
  56. android:background="@anim/frame" />
  57. </LinearLayout>
Copyright © Linux教程網 All Rights Reserved