Android实现圆圈倒计时 本文实例为大家分享了Android实现圆圈倒计时的具体代码,供大家参考,具体内容如下 1. 显示效果如下 2. 首先是创建shape的xml文件 在res/drawable目录下创建 shape_round_textview.xml文件,文件代码如下: ?xml version=1.0 encoding=UTF-8? shape xmln
本文实例为大家分享了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();
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。
沃梦达教程
本文标题为:Android实现圆圈倒计时


基础教程推荐
猜你喜欢
- Android实现短信验证码输入框 2023-04-29
- Flutter进阶之实现动画效果(三) 2022-10-28
- iOS开发使用XML解析网络数据 2022-11-12
- Android Compose自定义TextField实现自定义的输入框 2023-05-13
- MVVMLight项目Model View结构及全局视图模型注入器 2023-05-07
- iOS Crash常规跟踪方法及Bugly集成运用详细介绍 2023-01-18
- IOS获取系统相册中照片的示例代码 2023-01-03
- Android开发Compose集成高德地图实例 2023-06-15
- iOS开发 全机型适配解决方法 2023-01-14
- iOS中如何判断当前网络环境是2G/3G/4G/5G/WiFi 2023-06-18