Skip to content
项目

关于

用户按住时显示的按钮。主要用于控制音频录制状态(类似 Telegram、Viber 和 VK 中的按钮)。

设计与媒体

这些数字如何统计

实测星标增长

24小时
0
7天
0
15天
-1
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

HoldingButton

Android Arsenal

Button which is visible while user holds it. Main use case is controlling audio recording state (like in Telegram, Viber, VK).

Getting started

Add library as dependency to your build.gradle.

compile 'com.dewarder:holdingbutton:0.1.3'

How to use

  1. Wrap your layout with HoldingButtonLayout. It is simple FrameLayout inside.

     <com.dewarder.holdinglibrary.HoldingButtonLayout
         android:id="@+id/input_holder"
         android:layout_width="match_parent"
         android:layout_height="wrap_content">
         
         ...
      
         <ImageView
             android:id="@+id/start_record"
             android:layout_width="48dp"
             android:layout_height="match_parent"
             android:scaleType="center"
             android:src="@drawable/ic_mic_black_24dp"/>
    
         ...
    
     </com.dewarder.holdinglibrary.HoldingButtonLayout>
    
  2. Set app:hbl_holding_view property to id of view which would be translated to HoldingButton

     <com.dewarder.holdinglibrary.HoldingButtonLayout
         android:id="@+id/input_holder"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         app:hbl_holding_view="@+id/start_record">
    
  3. Set app:hbl_icon property to icon (usually it is the same as in translated view) which would be appeared in HoldingButton.

     <com.dewarder.holdinglibrary.HoldingButtonLayout
         android:id="@+id/input_holder"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         app:hbl_holding_view="@+id/start_record"
         app:hbl_icon="@drawable/ic_mic_black_24dp">
    
  4. Listen events

    
    mHoldingButtonLayout.addListener(new SimpleHoldingButtonLayoutListener() {
        @Override
        public void onOffsetChanged(float offset, boolean isCancel) {
            mSlideToCancel.setTranslationX(-mHoldingButtonLayout.getWidth() * offset);
            mSlideToCancel.setAlpha(1 - SLIDE_TO_CANCEL_ALPHA_MULTIPLIER * offset);
        }
    });
    
  5. Enjoy!

    Check full example

All XML properties

  • hbl_enabled (isButtonEnabled/setButtonEnabled)

    Set enabled or disabled state of button only.

  • hbl_direction (getDirection/setDirection)

    Set direction of sliding. Possible directions are start (from right to left) and end (from left to right).

  • hbl_cancel_offset (getCancelOffset/setCancelOffset)

    Set minimum offset for cancel action.

  • hbl_icon (setIcon)

  • hbl_cancel_icon (setCancelIcon)

  • hbl_color (getColor/setColor)

  • hbl_cancel_color (getCancelColor/CancelColor)

  • hbl_radius (getRadius/setRadius)

  • hbl_second_radius (getSecondRadius/setSecondRadius)

  • hbl_second_alpha (getSecondAlpha/setSecondAlpha)

  • hbl_offset_x (getOffsetX/setOffsetX)

  • hbl_offset_y (getOffsetY/setOffsetY)

  • hbl_animate_holding_view (setAnimateHoldingView/isAnimateHoldingView)

License

Copyright (C) 2017 Artem Glugovsky

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

探索相关项目

加载中…