Android實(shí)現(xiàn)圓圈倒計(jì)時(shí)
本文實(shí)例為大家分享了Android實(shí)現(xiàn)圓圈倒計(jì)時(shí)的具體代碼,供大家參考,具體內(nèi)容如下
1. 顯示效果如下
2. 首先是創(chuàng)建shape的xml文件
在res/drawable目錄下創(chuàng)建 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
我自己做的在一個(gè)橫向布局的LinearLayout里面把倒計(jì)時(shí)放到最右邊(中間TextView的目的是把倒計(jì)時(shí)的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); ? ? ? ? //隱藏默認(rèn)標(biāo)題欄 ? ? ? ? if (getSupportActionBar() != null){ ? ? ? ? ? ? getSupportActionBar().hide(); ? ? ? ? } ? ? ? ? setContentView(R.layout.activity_state_mode); ? ? ? ?? ? ? ? ? tx_time = findViewById(R.id.time_down); ? ? ? ? //倒計(jì)時(shí)顯示 ? ? ? ? ValueAnimator animator = ValueAnimator.ofInt(50,0); ? ? ? ? //設(shè)置時(shí)間 ? ? ? ? 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(); ? ? ? ? }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android實(shí)現(xiàn)倒計(jì)時(shí)的方案梳理
- Android?使用flow實(shí)現(xiàn)倒計(jì)時(shí)的方式
- Android實(shí)現(xiàn)一個(gè)倒計(jì)時(shí)自定義控件
- Android自定義View實(shí)現(xiàn)隨機(jī)數(shù)驗(yàn)證碼
- Android自定義驗(yàn)證碼輸入框的方法實(shí)例
- Android實(shí)現(xiàn)短信驗(yàn)證碼輸入框
- Android滑動(dòng)拼圖驗(yàn)證碼控件使用方法詳解
- Android實(shí)現(xiàn)隨機(jī)生成驗(yàn)證碼
- OpenHarmony實(shí)現(xiàn)類Android短信驗(yàn)證碼及倒計(jì)時(shí)流程詳解
相關(guān)文章
Android操作系統(tǒng)的架構(gòu)設(shè)計(jì)分析
這篇文章主要介紹了Android操作系統(tǒng)的架構(gòu)設(shè)計(jì)分析,Android系統(tǒng)架構(gòu)分為L(zhǎng)inux內(nèi)核驅(qū)動(dòng)、C/C ++框架、Java框架、Java應(yīng)用程序,本文分別講解了它的作用,需要的朋友可以參考下2015-06-06Android中TabLayout+ViewPager 簡(jiǎn)單實(shí)現(xiàn)app底部Tab導(dǎo)航欄
TabLayout 是Android com.android.support:design庫(kù)的一個(gè)控件。本文主要給大家介紹TabLayout+ViewPager 簡(jiǎn)單實(shí)現(xiàn)app底部Tab布局,需要的的朋友參考下2017-02-02Android?實(shí)現(xiàn)自定義圓形進(jìn)度條的三種常用方法
這篇文章主要介紹了Android?實(shí)現(xiàn)自定義圓形進(jìn)度條的三種常用方法的相關(guān)資料,需要的朋友可以參考下2023-03-03Flutter實(shí)現(xiàn)笑嘻嘻的動(dòng)態(tài)表情的示例代碼
這篇文章主要為大家介紹了如何利用Flutter實(shí)現(xiàn)笑嘻嘻的動(dòng)態(tài)表情,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)Flutter有一定幫助,感興趣的可以了解一下2022-04-04簡(jiǎn)單說(shuō)說(shuō)Android中如何使用攝像頭和相冊(cè)
本篇文章主要介紹了簡(jiǎn)單說(shuō)說(shuō)Android中如何使用攝像頭和相冊(cè),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-05-05Android如何自定義升級(jí)對(duì)話框示例詳解
對(duì)話框是我們?cè)谄綍r(shí)經(jīng)常會(huì)遇到的一個(gè)功能,但自帶的對(duì)話框不夠美觀,大家一般都會(huì)自定義,下面這篇文章主要給大家介紹了關(guān)于Android如何自定義升級(jí)對(duì)話框的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來(lái)一起看看吧。2017-08-08Android利用CountDownTimer實(shí)現(xiàn)倒計(jì)時(shí)功能 Android實(shí)現(xiàn)停留5s跳轉(zhuǎn)到登錄頁(yè)面
這篇文章主要為大家詳細(xì)介紹了Android利用CountDownTimer實(shí)現(xiàn)倒計(jì)時(shí)功能,Android實(shí)現(xiàn)停留5s跳轉(zhuǎn)到登錄頁(yè)面,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07