Android实现圆圈倒计时

作者:零下37度5 时间:2022-08-03 15:03:29 

本文实例为大家分享了Android实现圆圈倒计时的具体代码,供大家参考,具体内容如下

1. 显示效果如下

Android实现圆圈倒计时

2. 首先是创建shape的xml文件

在res/drawable目录下创建 shape_round_textview.xml文件,文件代码如下:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval"
    android:useLevel="false">
    <solid
        android:color="#FFFCFC" />
    <stroke
        android:width="1dp"
        android:color="#7468BE"
    />
    <size
        android:width="50dp"
        android:height="50dp"
    />
</shape>

3.然后就是在Layout布局文件里面使用定义的shape

我自己做的在一个横向布局的LinearLayout里面把倒计时放到最右边(中间TextView的目的是把倒计时的TextView挤到最右边去 )显示如图:

Android实现圆圈倒计时

布局文件代码:

<LinearLayout
        android:layout_marginTop="20dp"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <ImageButton
            android:layout_marginLeft="10dp"
            android:id="@+id/go_back"
            android:layout_width="36dp"
            android:layout_height="36dp"
            android:background="@drawable/go_back"
            />
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            />
        <TextView
            android:layout_marginRight="10dp"
            android:id="@+id/time_down"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:text="50"
            android:textSize="15sp"
            android:gravity="center"
            android:background="@drawable/shape_round_textview"
            />

</LinearLayout>

4.最后是java文件里的代码

public class StateModeActivity extends AppCompatActivity {

    private TextView tx_time;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //隐藏默认标题栏
        if (getSupportActionBar() != null){
            getSupportActionBar().hide();
        }
        setContentView(R.layout.activity_state_mode);
        
        tx_time = findViewById(R.id.time_down);
        //倒计时显示
        ValueAnimator animator = ValueAnimator.ofInt(50,0);
        //设置时间
        animator.setDuration(50000);
        //均匀显示
        animator.setInterpolator(new LinearInterpolator());
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                int value = (Integer) animation.getAnimatedValue();
                tx_time.setText(value+"");
                if(value==0)
                    startActivity(new Intent(StateModeActivity.this,MainActivity.class));
            }
        });
        animator.start();
        }

来源:https://blog.csdn.net/NUC__xjx/article/details/124131725

标签:Android,倒计时
0
投稿

猜你喜欢

  • 基于集合的子集与集合的全排列的相关问题

    2023-09-23 07:03:46
  • 在WinForm中发送HTTP请求的实现方法

    2023-01-28 10:47:35
  • VC对自定义资源加密解密(AES)的详解

    2023-01-10 00:27:15
  • 详解C语言内核字符串转换方法

    2022-12-09 13:53:55
  • 基于MyBatis的简单使用(推荐)

    2021-10-14 14:59:46
  • gradle使用maven-publish发布jar包上传到私有maven配置

    2022-11-22 07:07:54
  • android中实现指针滑动的动态效果方法

    2023-10-07 15:54:44
  • Java中一个线程执行死循环有什么后果

    2022-05-24 00:28:35
  • Java遍历json字符串取值的实例

    2023-09-02 17:03:17
  • C#获取每个年,月,周的起始日期和结束日期的方法

    2023-11-11 20:53:45
  • C# Winform消息通知系统托盘气泡提示框ToolTip控件

    2023-01-13 23:31:02
  • c#字符串编码问题的处理解决

    2021-07-06 13:47:49
  • Spring实战之属性覆盖占位符配置器用法示例

    2023-02-02 00:05:30
  • Java MyBatis本地缓存原理详解

    2023-01-30 18:20:36
  • Java实现pdf转图片案例

    2022-08-11 21:45:41
  • RecyclerView实现横向滚动效果

    2023-11-24 02:26:30
  • java线程池合理设置最大线程数和核心线程数方式

    2021-06-19 22:02:31
  • SpringBoot全局配置long转String丢失精度的问题解决

    2023-02-19 22:58:49
  • Android通过应用程序创建快捷方式的方法

    2021-07-08 00:41:09
  • Java运行时环境之ClassLoader类加载机制详解

    2022-07-18 04:54:05
  • asp之家 软件编程 m.aspxhome.com