How to create a whatsapp like recording button with slide to cancel

前端 未结 5 1911
逝去的感伤
逝去的感伤 2020-12-11 02:07

As in whatsapp I need a recoding button and a slide to cancel and fade animation , I have searched for similar code but didn\'t got one. I am new to android programming any

5条回答
  •  臣服心动
    2020-12-11 02:45

    you can use the library that i have made RecordView

    it's easy to setup and it's simulates the same behavior like WhatsApp.

    Simply add the Views RecordView and RecordButton

    
    
    
    
    
    

    then in your Activity

        RecordView recordView = (RecordView) findViewById(R.id.record_view);
        RecordButton recordButton = (RecordButton) 
         findViewById(R.id.record_button);
    
        //IMPORTANT
        recordButton.setRecordView(recordView);
    

    lastly you can handle the Record States

    • onStart when start Recording
    • onCancel when swiping to cancel
    • onFinish when finishes record and it returns the recorded time in millis
    • onLessThanSecond when the record time <= 1Second

      recordView.setOnRecordListener(this);
      
      
          @Override
          public void onStart() {
              //Start Recording..
              Log.d("RecordView", "onStart");
          }
      
          @Override
          public void onCancel() {
              //On Swipe To Cancel
              Log.d("RecordView", "onCancel");
      
          }
      
          @Override
          public void onFinish(long recordTime) {
              //Stop Recording..
              String time = getHumanTimeText(recordTime);
              Log.d("RecordView", "onFinish");
      
              Log.d("RecordTime", time);
          }
      
          @Override
          public void onLessThanSecond() {
              //When the record time is less than One Second
              Log.d("RecordView", "onLessThanSecond");
          }
      

提交回复
热议问题