content:
1. Confirm the user's storage structure in the MYSQL database
2. Replace the placeholders in the UI prototype with entities
3. Completed the production of the bulletin board
Bulletin board features:
1. When the user slides the mouse to the left or right, the picture on the bulletin board will also slide forward or backward
2. Every five seconds will automatically jump to the next one
difficulty:
How to make the program execute a piece of code every five seconds
Program implementation:
control time
handler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); if (msg.what == 0) { if(index==num-1){ is.setImageResource(gonggao[0]); index=0; Log.d("MainActivity", "1"); }else{ is.setImageResource(gonggao[index+1]); index++; Log.d("MainActivity", "2"); } Log.d("MainActivity", "123456"); } } }; new Timer().schedule(new TimerTask() { @Override public void run() { // (1) 使用handler发送消息 Message message=new Message(); message.what=0; handler.sendMessage(message); } },0,5000);
Control finger swipe:
// Touch listener. Is.setOnTouchListener (new View.OnTouchListener () { @Override public boolean onTouch (View v, MotionEvent event) { // Judge whether to press if (event.getAction () == MotionEvent.ACTION_DOWN) { touchDownX = event.getX (); return true; } else if (event.getAction () == MotionEvent.ACTION_UP) { touchUpX = event.getX (); // slide from left to right if (touchUpX-touchDownX> 100) { index = index == 0? gonggao.length-1: index-1; / * Slide animation here. * / / ** / is.setImageResource (gonggao [index]); } else if (touchDownX-touchUpX> 100) { index = index == gonggao.length-1? 0: index + 1; / * Slide animation here. * / / ** / is.setImageResource (gonggao [index]); } return true; } return false; } });
Questions:
How to make pictures play smooth sliding pictures?