private String SrcPathConfigfileImage = "/sdcard/data/pic.txt"; private String lineImage; private int imageIndex = 0; private ArrayList<String> imageList; private ImageView slidingImage; private int period, delay; private Handler mHandler; private Runnable mUpdateResults; private Timer timer; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); slidingImage = (ImageView)findViewById(R.id.imageView1); imageList = new ArrayList<String>(); try { File file = new File(SrcPathConfigfileImage); BufferedReader bufferRead = new BufferedReader(new FileReader(file)); while ((lineImage = bufferRead.readLine()) != null) { String SrcPathImage = "/sdcard/data/pic/"+lineImage; imageList.add(SrcPathImage); } playImage(); } catch (Exception e) { e.printStackTrace(); Toast.makeText(MainActivity.this, "Failed! Image = " + e.getMessage(),Toast.LENGTH_LONG).show(); } mHandler = new Handler(); // Create runnable for posting mUpdateResults = new Runnable() { public void run() { playImage(); } }; //int period = 8000; // repeat every 4 sec. timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { public void run() { mHandler.post(mUpdateResults); } }, 1000, period); } public void playImage() { String srcTimePeriod = imageList.get(imageIndex % imageList.size()); String[] splitTimePeriod = srcTimePeriod.split(","); String srcPartPicture = splitTimePeriod[0]; period = Integer.parseInt(splitTimePeriod[1]); Log.d("value period", String.valueOf(period)); Bitmap bm = BitmapFactory.decodeFile(srcPartPicture); slidingImage.setImageBitmap(bm); imageIndex++; Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.custom_anim); slidingImage.startAnimation(rotateimage); }
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง