效果图
ScreenGif4.gif
可以通过旋转view或者直接拖动来控制进度。
根据旋转角度,音量的移动速度会改变
根据旋转角度,归位时候的速度会改变
实现流程
重写onMeasure(),使得高度为外部矩形的高度+padding。
重写onDraw(),绘制两个矩形和一个球。
重写onTouchEvent()判断是点击小球移动还是旋转控件移动,并且判断点击是控件左半部分还是右半部分,在手指抬起时,执行归为动画。
设置音量改变接口供外部使用。
使用
记得要在外层Linearlayout中要添加clipChildred=false。。
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:clipChildren="false"
tools:context=".MainActivity">
android:textSize="14sp"
android:textColor="#333333"
android:id="@+id/tv"
android:gravity="center"
android:layout_marginTop="100dp"
android:layout_marginBottom="20dp"
android:text="音量 :"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:id="@+id/voice"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
代码
public class ProgressView extends View {
private static final String TAG = "HappyVoiceView";
/**
* 外层矩形框画笔
*/
private Paint outRectPaint;
/**
* 内层矩形框画笔
*/
private Paint innerR