论坛首页 移动开发技术论坛

Frame布局FrameLayout & Frame动画AnimationDrawable 应用实例

浏览 6941 次
精华帖 (1) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2010-12-20   最后修改:2010-12-20
  1)FrameLayout常常与 merge 相关,关于他们各自的介绍,请参阅相关的文档。在这里,
用来合并两个透明的png图片,就像photoshop里图层合并一样。
  2)Frame动画animation-list,常常用于制作短片动画或用于进程进度的一个指示标识。

先附图如下:
   

下面是部分代码:

res/anim/scrolling.xml
<?xml version="1.0" encoding="utf-8"?>
 <animation-list xmlns:android="http://schemas.android.com/apk/res/android" id="selected" android:oneshot="false">
<item android:drawable="@drawable/ball1" android:duration="80" />
  <item android:drawable="@drawable/ball2" android:duration="80" />
  <item android:drawable="@drawable/ball3" android:duration="80" />
  <item android:drawable="@drawable/ball4" android:duration="80" />
  <item android:drawable="@drawable/ball5" android:duration="80" />
  <item android:drawable="@drawable/ball6" android:duration="80" />	
	
 </animation-list>


res/layout/main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_centerHorizontal="true"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/frame01">

		<ImageView android:src="@drawable/line"
			android:layout_width="300sp"
		    android:layout_height="200sp">
		</ImageView>
	
	
		<ImageView android:src="@drawable/bar"
			android:layout_width="300sp"
		    android:layout_height="200sp">
		</ImageView>


	</FrameLayout>
    
    
    
	<ImageView android:id="@+id/scrolling_anim"
	           android:layout_width="wrap_content"
	           android:layout_height="wrap_content"
	           android:gravity="center"
	           android:layout_centerHorizontal="true"
	           android:layout_below="@id/frame01"
	           android:layout_marginTop="15sp"/> 
</RelativeLayout>




package com.sunflower;

import java.util.Timer;
import java.util.TimerTask;


import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.widget.ImageView;

public class FrameActivity extends Activity {
	    /** Called when the activity is first created. */
	    @Override
	    public void onCreate(Bundle icicle) {
	        super.onCreate(icicle);
	        setContentView(R.layout.main);
	        

	        ImageView img = (ImageView)findViewById(R.id.scrolling_anim);
	        img.setBackgroundResource(R.anim.scrolling); //设置动画的载体(画布)

	        
	       
	        
	        StopAnim mar2 = new StopAnim();
	        Timer t2 = new Timer(false);
	        t2.schedule(mar2, 10000); //10秒后停止动画
	        

	        
	    }

	    class StartUpAnim extends TimerTask {
	    	
	    	public void run() {
	        	ImageView img = (ImageView)findViewById(R.id.scrolling_anim);
	            // 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();
	    	}
	    }


	    class StopAnim extends TimerTask {

	    	
	    	public void run()
	    	{
	        	ImageView img = (ImageView)findViewById(R.id.scrolling_anim);
	            // Get the background, which has been compiled to an AnimationDrawable object.
	            AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();

	            // stop the animation (looped playback by default).
	            frameAnimation.stop();
	    	}
	    }


		@Override
		protected void onResume() {
			super.onResume();
			 StartUpAnim mar = new StartUpAnim(); //放在这里执行是让frameAnimation有足够的时间取得画布(Images's background)
		        
		        
		       Timer t = new Timer(false);
		       t.schedule(mar, 1000);  //延迟1秒后才开始动画
		}





	}



附件是整个app project.
  • 大小: 13.9 KB
   发表时间:2010-12-25  
谢谢了 请问你有android的学习资料吗  ,我打算转android开发 哈
0 请登录后投票
论坛首页 移动开发技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics