android首页广告倒计时,(安卓APP)简单的首页广告倒计时实现代码

直接上代码。

activity_ad.xml

adActivity.java

public class adActivity extends AppCompatActivity implements Animation.AnimationListener,Runnable {

Handler handler=new Handler(){//处理者

@Override

public void handleMessage(Message msg) {

TextView textView= (TextView) findViewById(R.id.adtextview);//初始化控件

switch (msg.what){//按时间自动逐秒递减

case 1:

textView.setText("广告倒计时:4秒");

break;

case 2:

textView.setText("广告倒计时:3秒");

break;

case 3:

textView.setText("广告倒计时:2秒");

break;

case 4:

textView.setText("广告倒计时:1秒");

break;

case 5:

textView.setText("广告倒计时:0秒");

break;

}

super.handleMessage(msg);//发送消息指令

}

};

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_ad);

setAnimation();

Thread thread=new Thread(this);

thread.start();

}

private void setAnimation() {//渐变动画

ImageView imageView= (ImageView) findViewById(R.id.adimageview);

AlphaAnimation a=new AlphaAnimation(0.8f,1);

a.setDuration(5000);//时间

a.setAnimationListener(this);//配置监听器

imageView.startAnimation(a);//启动动画

}

@Override

public void onAnimationStart(Animation animation) {

}

@Override

public void onAnimationEnd(Animation animation) {

//当动画结束的时候跳转

startActivity(new Intent(adActivity.this,loginActivity.class));

finish();

}

@Override

public void onAnimationRepeat(Animation animation) {

}

@Override

public void run() {//线程处理倒计时问题

for (int i=1;i<=5;i++){

Message message=new Message();

try {

Thread.sleep(950);//线程休眠时间

} catch (InterruptedException e) {

e.printStackTrace();

}

message.what=i;

handler.sendMessage(message);//发送消息给处理者

}

}

}

这个可以实现首页广告倒计时的功能,有点不完善,但是努力做出来还是很不错的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值