android 自定义 ProgressBar (类似微博拍摄视频进度条)

哈哈哈 第一次写自定义啦。。。。。


/**
 * 视频进度条
 * 
 * @author 
 */
public class ProgressView extends View {


/**
* 标注点的颜色
*/
private int markingColor;


/**
* 标注点的位置
*/
private float markingPosition;


private Paint mPaint = new Paint();


public ProgressView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}


public ProgressView(Context context) {
this(context, null);
}


/**
* 获得自定义的样式属性

* @param context
* @param attrs
* @param defStyle
*/
public ProgressView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ProgressView, defStyle, 0);
markingColor = a.getColor(R.styleable.ProgressView_markingColor, Color.parseColor("#eb6100"));
markingPosition = a.getFloat(R.styleable.ProgressView_markingPosition, 0);
a.recycle();
}


@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}


@Override
protected void onDraw(Canvas canvas) {
float value = getMeasuredWidth() * (markingPosition / 10f);
mPaint.setColor(markingColor);
canvas.drawRect(value, 0, value + 8f, getMeasuredHeight(), mPaint);
}
}




attrs.xml

    <!-- 视频拍摄进度条属性 -->
   <declare-styleable name="ProgressView">
        <attr name="foregroundColor" format="color" />
        <attr name="markingColor" format="color" />
        <attr name="markingPosition" format="float" />
    </declare-styleable>

 



 然后在 布局文件里面引用:

别忘了 一定要引用 xmlns:custom="http://schemas.android.com/apk/res/com.usportnews.fanszone"我们的命名空间,后面的包路径指的是项目的package

     

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="3dp"
        android:layout_marginBottom="5dp"
        android:background="#24292d" >


        <ProgressBar
            android:id="@+id/movie_recorder_view_progressBar"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:progressDrawable="@drawable/viedo_progress" />


        <com.usportnews.fanszone.widget.ProgressView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            custom:foregroundColor="#ed6100"
            custom:markingPosition="4" >
        </com.usportnews.fanszone.widget.ProgressView>


        <ImageView
            android:id="@+id/movie_recorder_arrowImgId"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="1dp"
            android:background="@drawable/icon_viedo_progress_white" />
    </RelativeLayout>



哈哈哈  中间隔断 白点 都有辣  完工。。。。。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值