public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
    // 要使用 findViewById, 一定要使用 layout / *.xml 做為使用者介面
    setContentView( R.layout.main );
   
    // 取得 UI 介面中的 View 物件
    // 取得 View 物件後,再透過轉換成實際的物件
    ImageView ivPic = (ImageView)this.findViewById(R.id.widget10);  // 底圖
    ImageView iv = (ImageView)this.findViewById(R.id.widget28);
   
    // 設定 ImageView 的圖片來源
    ivPic.setImageResource( R.drawable.a2 );
    iv.setImageResource( R.drawable.icon );
    
    // 透明度動畫設定 (startAlpha, endAlpha)
    Animation am1 = new AlphaAnimation( 1, 0 );
    // 動畫開始到結束的執行時間 (1000 = 1 秒)
    am1.setDuration( 2000 );
    // 動畫重複次數 (-1 表示一直重複)
    am1.setRepeatCount( -1 );
    
    // 旋轉動畫設定 (startAngle, endAngle, rotateX, rotateY)
    Animation am2 = new RotateAnimation( 0, 360, 30, 30 );
    // 動畫開始到結束的執行時間 (1000 = 1 秒)
    am2.setDuration( 2000 );
    // 動畫重複次數 (-1 表示一直重複)
    am2.setRepeatCount( -1 );
    
    // 動畫集合
    AnimationSet am = new AnimationSet( false );
    am.addAnimation( am1 );
    am.addAnimation( am2 );
    
    // 圖片配置動畫
    iv.setAnimation(am);
    
    // 動畫開始
    am.startNow();
}

arrow
arrow
    全站熱搜

    狼翔月影 發表在 痞客邦 留言(1) 人氣()