1 @Override 2 protected void onCreate(Bundle savedInstanceState) { 3 super.onCreate(savedInstanceState); 4 setContentView(R.layout.activity_main); 5 6 logo = (ImageView)findViewById(R.id.imageView1); 7 //實例化logo控件 8 9 btndl = (Button)findViewById(R.id.button1); 10 btnzc = (Button)findViewById(R.id.Button01); 11 //實例化按鈕控件 12 13 btndl.setVisibility(View.INVISIBLE); 14 btnzc.setVisibility(View.INVISIBLE); 15 //設置按鈕不顯示 16 17 ScaleAnimation animation = new ScaleAnimation(0, 1, 0, 1,Animation.RELATIVE_TO_SELF, 0.5f,1, 0.5f); 18 19 /** 20 * 21 * @param fromX 起始x軸位置,0為最小,1為原始,float形 22 * @param toX 同上 23 * @param fromY 同上T 24 * @param toY 同上 25 * @param pivotXType 用來約束pivotXValue的取值。取值有三種:Animation.ABSOLUTE,Animation.RELATIVE_TO_SELF,Animation.RELATIVE_TO_PARENT 26 * Type:Animation.ABSOLUTE:絕對,如果設置這種類型,后面pivotXValue取值就必須是像素點;比如:控件X方向上的中心點,pivotXValue的取值mIvScale.getWidth() / 2f 27 * Animation.RELATIVE_TO_SELF:相對於控件自己,設置這種類型,后面pivotXValue取值就會去拿這個取值是乘上控件本身的寬度;比如:控件X方向上的中心點,pivotXValue的取值0.5f 28 * Animation.RELATIVE_TO_PARENT:相對於它父容器(這個父容器是指包括這個這個做動畫控件的外一層控件), 原理同上, 29 * @param pivotXValue 配合pivotXType使用,原理在上面 30 * @param pivotYType 同from/to 31 * @param pivotYValue 原理同上 32 */ 33 34 animation.setDuration(2000); 35 //設置持續時間 36 animation.setFillAfter(true); 37 //設置動畫結束之后的狀態是否是動畫的最終狀態,true,表示是保持動畫結束時的最終狀態 38 animation.setRepeatCount(0); 39 //設置循環次數,0為1次 40 logo.startAnimation(animation); 41 //開始動畫 42 43 myTimer = new Timer(); 44 45 /** 46 * 47 * 建立計時器 48 * 當logo動畫結束后 49 * 顯示按鈕 50 * 51 */ 52 53 myTimer.schedule(new TimerTask() { 54 55 @Override 56 public void run() { 57 // TODO Auto-generated method stub 58 runOnUiThread(new Runnable() { 59 public void run() { 60 btndl.setVisibility(View.VISIBLE); 61 btnzc.setVisibility(View.VISIBLE); 62 } 63 }); 64 } 65 }, 2000); 66 67 }