Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android開發 >> 關於android開發 >> SlidePictures,男同網pictures

SlidePictures,男同網pictures

編輯:關於android開發

SlidePictures,男同網pictures


 

package com.example.SlidePictures;

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

import com.example.flashingpictures.R;

import android.media.Image;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.text.format.Time;
import android.view.Menu;
import android.widget.ImageView;

public class MainActivity extends Activity {
    private Image image;
    //定義變化圖片
    int[] images={
        R.drawable.a,
        R.drawable.b,
        R.drawable.c,
        R.drawable.d,
        R.drawable.e,
    };
    //定義傳遞信息
    //0x開頭表示16進制
    int SING=0x11;
    //照片順序
    int num=0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        final ImageView image=(ImageView)findViewById(R.id.imageView);
        final Handler handler=new Handler(){

            @Override
            public void handleMessage(Message msg) {
                // TODO Auto-generated method stub
                super.handleMessage(msg);
                if(msg.what==SING){
                    image.setImageResource(images[num++]);
                    if(num>=4){
                        num=0;
                    }
                }
                
            }        
        };
        new Timer().schedule(new TimerTask() {
            
            @Override
            public void run() {
                // TODO Auto-generated method stub
                Message msg=new Message();
                msg.what=SING;
                handler.sendMessage(msg);
            }
        }, 0,2000);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

效果執行圖:

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved