自定义控件:DashedCircularProgress

本文介绍如何使用DashedCircularProgress自定义控件来实现动态进度显示效果,包括控件的基本配置、布局文件设置及简单的Java代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

DashedCircularProgress和圆形头一样都是自定义控件;

首先声明这个自定义控件是从github上找的;从上面下载下来之后运行环境是as,我用的是eclipse;

类库导过来也没办法用。最后直接一点一点复制过来了;

其实这个自定义控件不难;我们只需要知道他的几个参数即可;

DashedCircularProgress可以随意设置宽高,这个根据大家需求自己设置;包括图标,进度条颜色都是自己随意设置的;

 

首先是布局文件:

 

<!-- 	进度条最大值:custom:max="100" 
	进度条最小值:custom:min="0"
	动画持续时间:custom:duration="1000"
	外部环的颜色:custom:external_color=""
	进度条图标:custom:progress_icon=""
	 内圈(显示进度的)圆环颜色:base_color
	 内圈已完成部分的圆环颜色:progress_color -->
    <com.github.glomadrian.dashedcircularprogress.DashedCircularProgress
        android:id="@+id/simple"
        android:layout_width="300dp"
        android:layout_height="310dp"
        android:layout_centerInParent="true"
        custom:base_color="#6effffff"
        custom:duration="2000"
        custom:external_color="#1affffff"
        custom:max="100"
        custom:min="0"
        custom:progress_color="#ffffff"
        custom:progress_icon="@drawable/ic_launcher" >

        <TextView
            android:id="@+id/text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="100"
            android:textSize="25sp" />
    </com.github.glomadrian.dashedcircularprogress.DashedCircularProgress>


activity代码:

 

 

DashedCircularProgress progress = (DashedCircularProgress)this.findViewById(R.id.simple);
		TextView text = (TextView)this.findViewById(R.id.text);
		progress.setOnValueChangeListener(
                new DashedCircularProgress.OnValueChangeListener() {
                    @Override
                    public void onValueChange(float value) {
                        text.setText((int) value + "%");
                    }
                });
	
		progress.setValue(88);

 

 

简单的几行代码就可以搞定;主要是类库的导入,我这边已经导入好了,下面是源码,大家用的话可以直接复制;
源码下载地址:

http://download.youkuaiyun.com/detail/zheng_jiao/9506691

 

  

刻度样式进度条的载入控件, 除了刻度进度条外,其他任何部分都可自定义。项目地址:https://github.com/glomadrian/dashed-circular-progress 效果图:如何使用:<com.github.glomadrian.dashedcircularprogress.DashedCircularProgress         android:layout_width="300dp"         android:layout_height="300dp">         //这里你可以添加任意View,他将显示在控件的中心位置     </com.github.glomadrian.dashedcircularprogress.DashedCircularProgress>比如:<com.github.glomadrian.dashedcircularprogress.DashedCircularProgress         android:id="@ id/progress"                 android:layout_centerInParent="true"         android:layout_width="300dp"         android:layout_height="300dp"         custom:min="0"         custom:max="100"         custom:duration="3500"         custom:progress_icon="@drawable/android">         <TextView android:id="@ id/text"                 android:textSize="25sp"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                  android:text=""/>     </com.github.glomadrian.dashedcircularprogress.DashedCircularProgress>添加了一个用于显示进度的Textview。 你也可以添加ImageView等任何View。java代码:progress = (DashedCircularProgress)this.findViewById(R.id.progress); text = (TextView)this.findViewById(R.id.text); progress.setOnValueChangeListener( new DashedCircularProgress.OnValueChangeListener() {//监听进度值的变化,     @Override     public void onValueChange(float value) {         text.setText((int) value   "%");显示进度值     } }); progress.setValue(50);//设置当前的进度值为50。注意progress.setValue()设置的并不是进度的百分比。而要知道进度完成的百分比,你还需要设置progress.setMax(),progress.setMin() 即进度的最大值、最小值。属性说明:external_color  外圈环的颜色base_color    内圈(显示进度的)环颜色progress_color  内圈已完成部分的环颜色max   进度最大值min   进度最小值progress_icon  设置顶端的图标duration  进度改变时,需要多长时间的动画达到这个值
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值