Android自定义控件篇 圆形倒计时

一、效果图

在这里插入图片描述

二、自定义样式 attrs.xml

 <declare-styleable name="AdCountDownView">
        <!--控制广告时间-->
        <attr name="AD_Time" format="integer"/>
        <!--是否需要显示文字 eg:是3秒 还是3-->
        <attr name="If_Need_Text" format="boolean"/>
        <!--动画圆的半径-->
        <attr name="Radius" format="dimension"/>
        <!--控制view是有背景还是没有背景 0:无背景  1 :有背景-->
        <attr name="Flag" format="integer"/>
        <!--倒计时文字的颜色-->
        <attr name="Text_Color" format="color"/>
        <!--倒计时文字的大小-->
        <attr name="Text_Size" format="dimension"/>
        <!--动画圆的颜色-->
        <attr name="StrokeCircleColor" format="color"/>
        <!--背景圆的颜色-->
        <attr name="SolidCircleColor" format="color"/>
        <!--动画圆的描边宽度-->
        <attr name="StrokeWidth" format="dimension"/>
        <!--是否有间隙-->
        <attr name="hasGap" format="boolean"/>
    </declare-styleable>

三、XML布局

 <com.midu.tele.widget.AdCountDownView
            android:id="@+id/AdCountDownView"
            android:layout_gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:Flag="1"
            app:Text_Color="@color/white"
            app:Text_Size="18sp"
            app:SolidCircleColor="#333333"
            app:StrokeCircleColor="#9F333333"
            app:Radius="40dp"
            app:If_Need_Text="false"/>

四、Activity界面设置

        //开启动画
        AdCountDownView mAdCountDownView = findViewById(R.id.AdCountDownView);
        //设置倒计时秒数
        mAdCountDownView.setAdTime(3);
        //设置样式
        //mAdCountDownView.setmStrokeCircleColor(Color.YELLOW);
		
		//开启倒计时(默认开启,重新启动可调用)
        //mAdCountDownView.anim();
        
        //动画结束的回调,需要Activity实现接口 AdCountDownView.AnimEndCallBack 
        mAdCountDownView.setEndCallBack(this);
		
		//使用代码来控制中英文或者其他语言
		//mAdCountDownView.setNeedTextStr("s");
		//mAdCountDownView.setNeedTextStr("秒");
	
		@Override
   		public void animEnd() {
   
        //倒计时结束隐藏自定义控件
        mAdCountDownView.setVisibility(View.INVISIBLE);
        }

五、自定义圆形倒计时

import android.animation.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

其子昱舟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值