您的位置:首页 > 移动开发 > Android开发

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

2016-03-16 15:22 344 查看
哈哈哈 第一次写自定义啦。。。。。

/**

* 视频进度条

*

* @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>

哈哈哈 中间隔断 白点 都有辣 完工。。。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: