網站首頁 編程語言 正文
本文實例為大家分享了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();
? ? ? ? }
原文鏈接:https://blog.csdn.net/NUC__xjx/article/details/124131725
相關推薦
- 2022-07-11 go語言環境搭建
- 2022-11-17 Android四種常見布局方式示例教程_Android
- 2022-04-19 運行 npm run xxx 的時候都執行了些什么
- 2024-01-15 jquery獲取dom元素身上的綁定事件
- 2024-01-05 IDEA創建導入Maven工程時出錯Connection refused to host
- 2022-10-17 Python實現在一行中交換兩個變量_python
- 2022-07-17 SQL實現查詢某字段的值為空的記錄_MsSql
- 2022-02-18 解決scrapy爬蟲報錯 pymongo.errors.DuplicateKeyError: E11
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支