progressview

1.定义图片

@drawable/progress_rect1

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <solid android:color="#FFFFFFFF" />

    <gradient
        android:angle="90"
        android:endColor="#FFFFFFFF"
        android:startColor="#FFFFFFDE"
        android:type="linear" />

    <stroke
        android:dashWidth="2px"
        android:width="2px"
        android:color="#FF616D73" />

    <corners android:radius="12dp" />

</shape>

@drawable/progress_rect2

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <solid android:color="#FF62CCDE" />

    <gradient
        android:angle="90"
        android:endColor="#FF98D7E8"
        android:startColor="#FF65CADE"
        android:type="linear" />

    <stroke
        android:dashWidth="2px"
        android:width="2px"
        android:color="#FF616D73" />

    <corners android:radius="12dp" />

</shape>

2.xml布局文件引用

        <com.huawei.roadmng.login.ProcessView
            android:id="@+id/loadingProcess"
            android:layout_width="500dip"
            android:layout_height="32dip"
            android:layout_marginTop="25dip"
            android:background="@drawable/progress_rect1"
            android:src="@drawable/progress_rect2" />

3.progressview处理



import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageButton;


public class ProcessView extends ImageButton
{
    /**
     * 用于绘制进度条
     */
    private static final int PERCENT = 100;
    
    /**
     * 进度条的进度百分比
     */
    private int precent;
    
    /**
     * 进度条的宽度
     */
    private int mWidth;
    
    /**
     * 进度条的高度
     */
    private int mHeight;
    
    /**
     * 背景
     */
    private Drawable mBackGround;
    
    /**
     * 前景
     */
    private Drawable mImg;
    
    /** <默认构造函数>
     * @param context Context
     */
    public ProcessView(Context context)
    {
        super(context);
    }
    
    /** <默认构造函数>
     * @param context Context
     * @param attrs AttributeSet
     */
    public ProcessView(Context context, AttributeSet attrs)
    {
        super(context, attrs);
    }
    
    /**
     * {@inheritDoc}
     */
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
    {
        int height = View.MeasureSpec.getSize(heightMeasureSpec);
        int width = View.MeasureSpec.getSize(widthMeasureSpec);
        setMeasuredDimension(width, height);
    }
    
    /**
     * {@inheritDoc}
     */
    public void onDraw(Canvas canvas)
    {
        if (mBackGround == null)
        {
            mImg = this.getDrawable();
            mBackGround = this.getBackground();
        }
        if (mWidth == 0 || mHeight == 0)
        {
            mWidth = getMeasuredWidth();
            mHeight = getMeasuredHeight();
        }
        
        mBackGround.draw(canvas);
        canvas.clipRect(0, 0, mWidth * precent / PERCENT, mHeight);
        mImg.draw(canvas);
        //            canvas.clipRect(0, 0, mWidth, mHeight);
    }
    
    /**
     * {@inheritDoc}
     */
    @Override
    protected void onFinishInflate()
    {
        super.onFinishInflate();
        mImg = this.getDrawable();
        mBackGround = this.getBackground();
    }
    
    /** 
     * 设置进度
     * @param curPrecent int
     * @see [类、类#方法、类#成员]
     */
    public void setProgress(int curPrecent)
    {
        precent = curPrecent < 0 ? 0 : curPrecent > 100 ? 100 : curPrecent;
        invalidate();
    }
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值