2014-07-27 56 views
0

我試圖添加一個動畫(不知道如果這將是一個合適的詞)的海灘波,當我的應用程序加載其第一個screen.I正在開發一個假日應用程序,並已設置圖像(沙的靜態圖像)作爲背景。我期待將沙圖像作爲背景,並具有波浪撞擊岸邊的效果。如何實現這一目標?我希望此圖片中的波動 - >http://www.wallpapervortex.com/wallpaper-23493_beach_sand_sand_beach.html#.U9Rr2fldW8A如何在Android應用中爲背景帶來動畫效果?

+0

你有沒有想過使用videoview的? –

+0

@harvey_slash通過VideoView類後,我認爲不適合我的要求。根據我的理解,VideoView和MediaController提供了暫停選項,但我不需要這些功能。 – Sri

回答

0

將每個幀都作爲可繪製文件夾中的單獨圖像。在此之後,使用XML來定義幀(例如,ANIMATED.xml)

<animation-list android:id="@+id/selected" android:oneshot="false"> 
    <item android:drawable="@drawable/0" android:duration="50" /> 
    <item android:drawable="@drawable/1" android:duration="50" /> 
    <item android:drawable="@drawable/2" android:duration="50" /> 
    <item android:drawable="@drawable/3" android:duration="50" /> 
    <item android:drawable="@drawable/4" android:duration="50" /> 
    <item android:drawable="@drawable/5" android:duration="50" /> 
</animation-list> 

,並使其動畫,使用:

// Load the ImageView that will host the animation and 
// set its background to our AnimationDrawable XML resource. 
ImageView img = (ImageView)findViewById(R.id.moving_image); 
img.setBackgroundResource(R.drawable.ANIMATED.xml); 

// Get the background, which has been compiled to an AnimationDrawable object. 
AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground(); 

// Start the animation (looped playback by default). 
frameAnimation.start();