Như trong whatsapp tôi cần một nút mã hóa và một slide để hủy bỏ và làm mờ hoạt ảnh, tôi đã tìm kiếm mã tương tự nhưng không có. Tôi mới tham gia lập trình Android bất kỳ trợ giúp hoặc liên kết nào có thể hữu ích.Làm thế nào để tạo một nút ghi như whatsapp với slide để hủy
10
A
Trả lời
14
tôi đã tạo ra một github project.You có thể có một cái nhìn vào nó https://github.com/sarathnk/Audio
audioSendButton.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) slideText
.getLayoutParams();
params.leftMargin = dp(30);
slideText.setLayoutParams(params);
ViewProxy.setAlpha(slideText, 1);
startedDraggingX = -1;
// startRecording();
startrecord();
audioSendButton.getParent()
.requestDisallowInterceptTouchEvent(true);
recordPanel.setVisibility(View.VISIBLE);
} else if (motionEvent.getAction() == MotionEvent.ACTION_UP
|| motionEvent.getAction() == MotionEvent.ACTION_CANCEL) {
startedDraggingX = -1;
stoprecord();
// stopRecording(true);
} else if (motionEvent.getAction() == MotionEvent.ACTION_MOVE) {
float x = motionEvent.getX();
if (x < -distCanMove) {
stoprecord();
// stopRecording(false);
}
x = x + ViewProxy.getX(audioSendButton);
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) slideText
.getLayoutParams();
if (startedDraggingX != -1) {
float dist = (x - startedDraggingX);
params.leftMargin = dp(30) + (int) dist;
slideText.setLayoutParams(params);
float alpha = 1.0f + dist/distCanMove;
if (alpha > 1) {
alpha = 1;
} else if (alpha < 0) {
alpha = 0;
}
ViewProxy.setAlpha(slideText, alpha);
}
if (x <= ViewProxy.getX(slideText) + slideText.getWidth()
+ dp(30)) {
if (startedDraggingX == -1) {
startedDraggingX = x;
distCanMove = (recordPanel.getMeasuredWidth()
- slideText.getMeasuredWidth() - dp(48))/2.0f;
if (distCanMove <= 0) {
distCanMove = dp(80);
} else if (distCanMove > dp(80)) {
distCanMove = dp(80);
}
}
}
if (params.leftMargin > dp(30)) {
params.leftMargin = dp(30);
slideText.setLayoutParams(params);
ViewProxy.setAlpha(slideText, 1);
startedDraggingX = -1;
}
}
view.onTouchEvent(motionEvent);
return true;
}
});
3
tôi đã triển khai nút gửi như trong ứng dụng whatsapp mà có thể là trong gửi nhà nước hoặc nhà nước kỷ lục. Bạn có thể xem nó ở đây trên blog post của tôi.
Cách sử dụng rất đơn giản.
<com.gunhansancar.android.animbutton.AnimButton
android:id="@+id/animButton"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_width="50dp"
android:layout_height="50dp"
app:first="@drawable/ic_mic"
app:second="@drawable/ic_send" />
Bạn chỉ cần đặt độ phân giải đầu tiên và thứ hai. Và bạn cũng phải thiết lập trạng thái bằng cách gọi phương thức goToState().
2
bạn có thể sử dụng thư viện mà tôi đã thực hiện RecordView
thật dễ dàng để thiết lập và nó mô phỏng hành vi tương tự như WhatsApp.
Chỉ cần thêm Views RecordView
và RecordButton
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/parent_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.devlomi.recordview.MainActivity">
<com.devlomi.record_view.RecordView
android:id="@+id/record_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@id/record_button"
app:slide_to_cancel_arrow="@drawable/ic_keyboard_arrow_left"
app:slide_to_cancel_text="Slide To Cancel"
app:slide_to_cancel_margin_right="10dp"/>
<com.devlomi.record_view.RecordButton
android:id="@+id/record_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="@drawable/bg_mic"
android:scaleType="centerInside"
app:src="@drawable/ic_mic_white"
/>
sau đó trong hoạt động của bạn
RecordView recordView = (RecordView) findViewById(R.id.record_view);
RecordButton recordButton = (RecordButton)
findViewById(R.id.record_button);
//IMPORTANT
recordButton.setRecordView(recordView);
cuối cùng bạn có thể xử lý Hoa Ghi
- onStart khi bắt đầu ghi
- onCancel khi trượt để hủy bỏ
- onFinish khi kết thúc kỷ lục và nó trả về thời gian ghi trong millis
onLessThanSecond khi thời gian kỷ lục < = 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"); }
Các vấn đề liên quan
- 1. Làm thế nào để làm slide để nút trong android
- 2. Làm thế nào để nhóm thông báo android như whatsapp?
- 3. Làm cách nào để tạo nút hủy trong simple_form?
- 4. Làm thế nào để tạo một slide-Out Navigation Panel trong ios
- 5. Làm thế nào để tạo một mảng bản ghi sumpy?
- 6. Làm thế nào để tạo một nút Wrapping trong WPF
- 7. Nén video như whatsapp
- 8. Làm thế nào để hủy bỏ một UIWebView?
- 9. JsTree làm thế nào để tạo ra một nút gốc
- 10. Làm thế nào để tạo một nút tròn trong Swift?
- 11. Làm thế nào để đạt được 'phương tiện truyền thông không tồn tại' như whatsapp?
- 12. Làm thế nào để tạo ra một nút tròn với một lớp phủ góc
- 13. Kéo để thay đổi slide hình ảnh với jquery như trong iphone
- 14. javascript để tạo một nút với onclick
- 15. Làm thế nào để thực hiện Video cắt tỉa trên Android như instagram hoặc Whatsapp?
- 16. Làm thế nào để mã một segue tùy chỉnh mà "slide" giữa View Controller?
- 17. Làm thế nào để tạo một nút trùng lặp từ một nút trong Neo4j?
- 18. Làm thế nào để thay đổi một hình ảnh trên một slide trong Latex?
- 19. Làm thế nào để làm cho một nút hoạt động như một liên kết trong ERB?
- 20. Làm thế nào để redeclare một tài sản như đọc-ghi trong UIResponder subclass với swift?
- 21. UIPopover Làm cách nào để tạo một cửa sổ bật lên với các nút như thế này?
- 22. Làm thế nào để hủy bỏ một jquery.load()?
- 23. Xác thực Whatsapp hoạt động như thế nào?
- 24. Làm cách nào để kích hoạt nút hủy trong UISearchBar?
- 25. Làm thế nào để sử dụng AVCaptureSession với Slide Over và Split View trong iOS 9?
- 26. Làm thế nào để hủy bỏ NSBlockOperation
- 27. Làm thế nào để tạo một nút Bootstrap với chiều rộng đầy đủ?
- 28. Làm thế nào để phá hủy một datatable?
- 29. Làm thế nào để hủy bỏ một JobIntentService
- 30. Làm thế nào để làm cho một nút xuất hiện như thể nó được nhấn?
Grea t Làm việc ở đây tôi muốn lưu trữ âm thanh đã ghi –