一:布局界面
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#cccccc"
tools:context=".MainActivity" >
<com.example.com.circleimg.CircleImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tv_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:padding="10dp"
android:text="跳过" />
</RelativeLayout>
二:界面代码:
package com.example.com.circleimg;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class MainActivity extends Activity implements OnClickListener{
//开源库中circleImageView
CircleImageView civ;
TextView tv_next;
MyCountDownTimer mt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
civ = (CircleImageView) findViewById(R.id.img);
tv_next=(TextView) findViewById(R.id.tv_next);
tv_next.setOnClickListener(this);
civ.setImageDrawable(getResources().getDrawable(R.drawable.ss));
mt=new MyCountDownTimer(10000, 1000);
mt.start();
}
class MyCountDownTimer extends CountDownTimer {
/**
*
* @param millisInFuture
* 表示以毫秒为单位 倒计时的总数
*
* 例如 millisInFuture=1000 表示1秒
*
* @param countDownInterval
* 表示 间隔 多少微秒 调用一次 onTick 方法
*
* 例如: countDownInterval =1000 ; 表示每1000毫秒调用一次onTick()
*/
public MyCountDownTimer(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
// TODO Auto-generated constructor stub
}
@Override
public void onTick(long millisUntilFinished) {
// TODO Auto-generated method stub
long time= (millisUntilFinished/1000);
tv_next.setText("剩余时间:"+(millisUntilFinished/1000));
}
@Override
public void onFinish() {
// TODO Auto-generated method stub
tv_next.setText("剩余时间:0");
startActivity(new Intent(MainActivity.this,SecondActivity.class));
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.tv_next:
mt.cancel();
mt.onFinish();
break;
}
}
}
三:效果图