广告
返回顶部
首页 > 资讯 > 移动开发 >Android实现圆圈倒计时
  • 545
分享到

Android实现圆圈倒计时

Android倒计时 2022-11-13 14:11:04 545人浏览 安东尼
摘要

本文实例为大家分享了Android实现圆圈倒计时的具体代码,供大家参考,具体内容如下 1. 显示效果如下 2. 首先是创建shape的xml文件 在res/drawable目录下创

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

1. 显示效果如下

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挤到最右边去 )显示如图:

布局文件代码:

<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();
        }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程网。

--结束END--

本文标题: Android实现圆圈倒计时

本文链接: https://www.lsjlt.com/news/172181.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作