抖音最近很火,可以说是app界的方向标。各种模仿也是层出不穷,最近项目有一个需求,需要做视频截取,两边拖动,选取中间的视频部分。
效果如下:
image.png
实现思路:通过自定义view 根据手指onTouch 坐标动态刷新ondraw 绘制刷新的视图,回调对应的区域阀值。
自定义拖动视图SeekView
public class VideoSliceSeekBar extends View {
enum SelectThumb {
//没有选中滑块
SELECT_THUMB_NONE,
//选中左边滑块
SELECT_THUMB_LEFT,
//选中右边滑块
SELECT_THUMB_RIGHT,
}
public VideoSliceSeekBar(Context context) {
this(context, null);
}
public VideoSliceSeekBar(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public VideoSliceSeekBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initValue();
}
上面定义了对应滑动的枚举,左边滑动view 右边以及另外的区域
private void initValue() {
paintThumb.setAntiAlias(true);
paintThumb.setFilterBitmap(true);
int resSweepLeft = R.drawable.ic_produce_cut_left;
thumbSliceLeft = BitmapFactory.decodeResource(getResources(), resSweepLeft);
int resSweepRight = R.drawable.ic_produce_cut_right;
thumbSliceRight = BitmapFactory.decodeResource(getResources(), resSweepRight);
int resFrame = R.drawable.ic_produce_cut_frame;
thumbFrame = BitmapFactory.decodeResource(getResources(), resFrame);
topBottomPadding = DensityUtil.dp2px(getContext(), 6);
progress = ObjectAnimator.ofFloat(this, "progress", 0).setDuration(400);
progress.setInterpolator(new LinearInterpolator());
<