日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

Android實現圓圈倒計時_Android

作者:零下37度5 ? 更新時間: 2022-10-04 編程語言

本文實例為大家分享了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

欄目分類
最近更新