进度条效果,参考部分代码实现,自定义可以再丰富些
解决的问题:1、ProgressBar圆角会被裁剪的问题,特别是两头的圆角;
自定义样式:
<declare-styleable name="ProgressWithNum">
<attr name="textSize" format="dimension" />
<attr name="textColor" format="color" />
<attr name="lineHeight" format="dimension" />
<attr name="lineStartColor" format="color" />
<attr name="lineEndColor" format="color" />
<!--进度条背景颜色-->
<attr name="bgLineColor" format="color" />
</declare-styleable>
代码:
package com.test.view;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.widget.ProgressBar;
import com.test.upload.R;
import com.test.upload.Utils;
/**
* 带数字百分比进度条
*/
public class ProgressWithNum extends ProgressBar {
//各种控件属性的默认值
//字体大小
private static final int DEFAULT_TEXT_SIZE = 15;
//字体颜色
private static final int DEFAULT_TEXT_COLOR = 0XF