发布网友 发布时间:2022-04-21 14:00
共2个回答
热心网友 时间:2022-04-21 15:29
项目遇到需要实现按键点击同时,如果按住也能实现连续音量加的效果
本办法是通过按下标志开启线程固定间隔时间发送动作
重写setOnTouchListener事件
btn_bolumeup.setOnTouchListener(new OnTouchListener(){
@Override public boolean onTouch(View v, MotionEvent event) { Log.d("yj.chen","onTouch"); if(event.getAction() == MotionEvent.ACTION_DOWN) { Log.d("yj.chen","ACTION_DOWN"); longClicked = true; btn_bolumeup.setBackgroundResource (R.drawable.haier_pop_btn_nor_m);// Thread t = new Thread(){ @Override public void run(){ super.run(); while(longClicked) { sendcode = 24; sendkeyenvet(); try{ Thread.sleep(250); }catch(InterruptedException e){ e.printStackTrace(); } Log.d("yj.chen","run end"); } } }; t.start(); } else if(event.getAction() == MotionEvent.ACTION_UP) { btn_bolumeup.setBackgroundResource (R.drawable.touch_control_btn);//touch_control_btn haier_pop_btn_sel_m longClicked = false; Log.d("yj.chen","ACTION_UP"); } return true; } });热心网友 时间:2022-04-21 16:47
onTouchEvent