/**
*main主方法
*/
package com.example.timer2;
import com.bumptech.glide.Glide;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MainActivity extends Activity {
private int recLen = 6;
private TextView txtView;
private ImageView ivNumber;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
setContentView(R.layout.activity_main);
//
txtView = (TextView) findViewById(R.id.txtTime);
ImageView ivBackground = (ImageView) findViewById(R.id.ivBackground);
ivNumber = (ImageView) findViewById(R.id.ivNumber);
Glide.with(MainActivity.this).load(R.drawable.a).into(ivBackground);
handler.postDelayed(runnable, 1000);
}
Handler handler = new Handler();
Runnable runnable = new Runnable() {
@Override
public void run() {
if (recLen < 2) {
return;
}
recLen--;
//设置图片
switch (recLen) {
case 5:
Glide.with(MainActivity.this).load(R.mipmap.five).into(ivNumber);
break;
case 4:
Glide.with(MainActivity.this).load(R.mipmap.four).into(ivNumber);
break;
case 3:
Glide.with(MainActivity.this).load(R.mipmap.three).into(ivNumber);
break;
case 2:
Glide.with(MainActivity.this).load(R.mipmap.two).into(ivNumber);
break;
case 1:
Glide.with(MainActivity.this).load(R.mipmap.one).into(ivNumber);
break;
}
//txtView.setText("" + recLen);
handler.postDelayed(this, 1000);
}
};
}
/**
*XML布局两个framelayout
*/
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#212021"
android:orientation="vertical"
tools:context="${relativePackage}.${activityClass}" >
<FrameLayout
android:id="@+id/fl_tip"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true" >
<ImageView
android:id="@+id/ivBackground"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:background="@android:color/transparent" >
<TextView
android:id="@+id/txBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10px"
android:text="张三"
android:textColor="#ffffff"
android:textSize="20px" />
<ImageView
android:id="@+id/ivNumber"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginBottom="62dp"
android:layout_marginLeft="113dp"
android:layout_marginTop="150px" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="10px"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/txReady"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="倒计时即将开始"
android:textColor="#ffffff"
android:textSize="24px" />
<TextView
android:id="@+id/txKilo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4px"
android:text="开始"
android:textColor="#ffffff"
android:textSize="18px" />
</LinearLayout>
</FrameLayout>
</FrameLayout>
</LinearLayout>