codol全民夺宝大作战没有抢到需要支付费用吗

3844人阅读
android(72)
在sina里看到了什么全民夺宝的链接,然后忍不住1元的诱惑被坑了10多块,什么都没有抽到,但是还是有人抽到了不知道是不是坑爹的,然后也就动手做一下倒计时的功能。
先看全民夺宝:
说起这个功能是不是感觉so easy,然后就以此来搞2个倒计时效果,顺便也学习一下CountDownTimer的使用。
哈哈,看看今天实现的效果图:
回顾 常用的倒计时方式
Timer与TimerTask(Java实现)
public class timerTask extends Activity{
private int recLen = 11;
private TextView txtV
Timer timer = new Timer();
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.timertask);
txtView = (TextView)findViewById(R.id.txttime);
timer.schedule(task, 1000, 1000);
TimerTask task = new TimerTask() {
public void run() {
runOnUiThread(new Runnable() {
public void run() {
txtView.setText(""+recLen);
if(recLen & 0){
timer.cancel();
txtView.setVisibility(View.GONE);
TimerTask与Handler(不用Timer的改进型)
public class timerTask extends Activity{
private int recLen = 11;
private TextView txtV
Timer timer = new Timer();
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.timertask);
txtView = (TextView)findViewById(R.id.txttime);
timer.schedule(task, 1000, 1000);
final Handler handler = new Handler(){
public void handleMessage(Message msg){
switch (msg.what) {
txtView.setText(""+recLen);
if(recLen & 0){
timer.cancel();
txtView.setVisibility(View.GONE);
TimerTask task = new TimerTask() {
public void run() {
Message message = new Message();
message.what = 1;
handler.sendMessage(message);
Handler与Message(不用TimerTask)
public class timerTask extends Activity{
private int recLen = 11;
private TextView txtV
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.timertask);
txtView = (TextView)findViewById(R.id.txttime);
Message message = handler.obtainMessage(1);
handler.sendMessageDelayed(message, 1000);
final Handler handler = new Handler(){
public void handleMessage(Message msg){
switch (msg.what) {
txtView.setText("" + recLen);
if(recLen & 0){
Message message = handler.obtainMessage(1);
handler.sendMessageDelayed(message, 1000);
txtView.setVisibility(View.GONE);
super.handleMessage(msg);
Handler与Thread(不占用UI线程)
public class timerTask extends Activity{
private int recLen = 11;
private TextView txtV
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.timertask);
txtView = (TextView)findViewById(R.id.txttime);
new Thread(new MyThread()).start();
final Handler handler = new Handler(){
public void handleMessage(Message msg){
switch (msg.what) {
txtView.setText("" + recLen);
super.handleMessage(msg);
public class MyThread implements Runnable{
public void run(){
while(recLen&0){
Thread.sleep(1000);
Message message = new Message();
message.what = 1;
handler.sendMessage(message);
}catch (Exception e) {
Handler与Runnable(最简单型)
public class timerTask extends Activity{
private int recLen = 11;
private TextView txtV
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.timertask);
txtView = (TextView)findViewById(R.id.txttime);
handler.postDelayed(runnable, 1000);
Handler handler = new Handler();
Runnable runnable = new Runnable() {
public void run() {
if(recLen&0){
txtView.setText("" + recLen);
handler.postDelayed(this, 1000);
回顾了以前最常使用的5种方法是不是觉得还是比较麻烦,要说最好的也就第5种。
使用案列(简单)
* 继承 CountDownTimer 防范
* 重写 父类的方法 onTick() 、 onFinish()
class MyCountDownTimer extends CountDownTimer {
* millisInFuture
表示以毫秒为单位 倒计时的总数
例如 millisInFuture=1000 表示1秒
* countDownInterval
表示 间隔 多少微秒 调用一次 onTick 方法
例如: countDownInterval =1000 ; 表示每1000毫秒调用一次onTick()
public MyCountDownTimer(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
public void onFinish() {
public void onTick(long millisUntilFinished) {
开始倒计时使用:CountDownTimer .start();
关闭:CountDownTimer .cancle();
这里拿两种情况来实现这功能,顺便也做成2个自定义view来使用。
布局界面图:
先看布局:
&?xml version="1.0" encoding="utf-8"?&
xmlns:android="/apk/res/android"
xmlns:tools="/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.losileeya.countdownmaster.MainActivity"
android:layout_marginTop="20dp"
android:gravity="center_horizontal"
android:orientation="vertical"
android:background="#AAA9AA"&
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="场景一:商品抢购"
android:textSize="24sp"
android:textColor="#D93552"
android:id="@+id/commodityBuyView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/&
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="场景二:短信验证码"
android:textSize="24sp"
android:textColor="#D93552"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="vertical"&
android:id="@+id/et_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/code_bg"
android:hint="请输入手机号"
android:padding="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:maxLength="11"
android:textSize="16sp"/&
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/et_msg_code"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="1"
android:background="@drawable/code_bg"
android:layout_marginLeft="50dp"
android:gravity="center"
android:id="@+id/time_button"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center"
我们先来 做短信验证码的倒计时功能:
思路就是:给按钮监听是否可点击,并且动态改变显示的文字,从而实现倒计时的效果。
package com.losileeya.countdownmaster.
import android.content.C
import android.os.CountDownT
import android.util.AttributeS
import android.view.LayoutI
import android.view.V
import android.widget.B
import android.widget.LinearL
import com.losileeya.countdownmaster.R;
* 自定义控件,实现验证码按钮倒计时功能。
* losileeya
public class TimeButton extends LinearLayout {
private Button timeB
private int default_time = 60*1000;
private TimeButtonCallBack timeB
private MyCountDownT
public TimeButton(Context context) {
this(context, null);
public TimeButton(Context context, AttributeSet attrs)
this(context, attrs, 0);
public TimeButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
timeButton = (Button) inflater.inflate(R.layout.view_time_button, this).findViewById(R.id.time);
initListerner();
* 暴露倒计时时间给使用者调
public void setTime(int millis){
this.default_time=
public void initListerner() {
timeButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (timeButtoncallback != null) {
if (timeButtoncallback.Start()) {
timeButton.setClickable(false);
mc = new MyCountDownTimer(default_time, 1000);
mc.start();
public void setTimeButtonCallBack(TimeButtonCallBack timeButtoncallback) {
this.timeButtoncallback = timeB
* 倒计时控件回调外部代码的接口。
public interface TimeButtonCallBack {
* 点击按钮后,开始计时前调用的方法。
* 返回true会开始计时,false会退出计时。
public boolean Start();
* 结束啦。
public void End();
* 数字发生变化了。
public void numChanged(int num);
* 继承 CountDownTimer 防范
* 重写 父类的方法 onTick() 、 onFinish()
class MyCountDownTimer extends CountDownTimer {
* millisInFuture
表示以毫秒为单位 倒计时的总数
例如 millisInFuture=1000 表示1秒
* countDownInterval
表示 间隔 多少微秒 调用一次 onTick 方法
例如: countDownInterval =1000 ; 表示每1000毫秒调用一次onTick()
public MyCountDownTimer(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
public void onFinish() {
mc.cancel();
timeButton.setText("获取验证码");
timeButton.setClickable(true);
if (timeButtoncallback != null) {
timeButtoncallback.End();
public void onTick(long millisUntilFinished) {
timeButton.setText(millisUntilFinished/1000 + "秒后重新获取");
if (timeButtoncallback != null) {
timeButtoncallback.numChanged((int)millisUntilFinished/1000);
接下来是仿全民夺宝抢购倒计时功能:
实现思路:一整个view包含商品图片、商品描述,项目实际开发中会通过接口获取值,然后就是一个倒计时效果,倒计时结束后变为揭晓获奖答案。
package com.losileeya.countdownmaster.
import android.content.C
import android.os.CountDownT
import android.os.H
import android.util.AttributeS
import android.view.LayoutI
import android.view.V
import android.widget.LinearL
import android.widget.TextV
import com.losileeya.countdownmaster.R;
* Created by losileeya on .
public class CommodityBuyView extends LinearLayout {
private TextView tv_goods_desc,tv_status,tv_
private MyCountDownT
private LinearLayout ll_
public CommodityBuyView(Context context) {
this(context, null);
public CommodityBuyView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
public CommodityBuyView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initView(context);
* find 控件,初始化
private void initView(Context context) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view=inflater.inflate(R.layout.view_commodity_buying,this);
tv_goods_desc= (TextView)view.findViewById(R.id.tv_goods_desc);
tv_status= (TextView) view.findViewById(R.id.tv_status);
tv_awardee= (TextView) view.findViewById(R.id.tv_awardee);
ll_result= (LinearLayout) view.findViewById(R.id.ll_result);
tv_status=(TextView) view.findViewById(R.id.tv_status);
mc = new MyCountDownTimer(280000, 100);
mc.start();
* 继承 CountDownTimer 防范
* 重写 父类的方法 onTick() 、 onFinish()
class MyCountDownTimer extends CountDownTimer {
* millisInFuture
表示以毫秒为单位 倒计时的总数
例如 millisInFuture=1000 表示1秒
* countDownInterval
表示 间隔 多少微秒 调用一次 onTick 方法
例如: countDownInterval =1000 ; 表示每1000毫秒调用一次onTick()
public MyCountDownTimer(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
public void onFinish() {
tv_status.setText("揭晓中....");
new Handler().postDelayed(new Runnable() {
public void run() {
tv_status.setVisibility(View.GONE);
ll_result.setVisibility(View.VISIBLE);
tv_awardee.setText(awardee);
* 处理时间倒计时进行页面刷新
* millisUntilFinished
public void onTick(long millisUntilFinished) {
int ss = 1000;
int mi = ss * 60;
long minute = millisUntilFinished/
long second = (millisUntilFinished- minute * mi) /
long milliSecond = millisUntilFinished
- minute * mi - second *
String strMinute = minute & 10 ? "0" + minute : "" +
String strSecond = second & 10 ? "0" + second : "" +
String strMilliSecond = milliSecond & 10 ? "0" + milliSecond : "" + milliS
strMilliSecond = milliSecond &100 ? strMilliSecond.substring(0,strMilliSecond.length()-1) : "" + strMilliS
tv_status.setText(strMinute + " 分 "+strSecond+"秒"+strMilliSecond);
* 设置获奖人
public void setAwardee(String awardee){
this.awardee=
就写到这里吧,困觉。
其实代码是很简单的,但是效果也还算可以的,项目过程中也或许用得到,至少很多人可能都不知道CountDownTimer这个东东,所以兴趣是最好的老师。如果你觉得还行的话,帮忙顶起来这将是对我最大的鼓励。
come on,enjoy it.
demo传送门:
这里最后推荐一个倒计时控件:
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:120238次
积分:2336
积分:2336
排名:第11402名
原创:84篇
转载:20篇
评论:153条
文章:10篇
阅读:24855
阅读:3196
阅读:12749
文章:15篇
阅读:30812全民夺宝没有抢到需要支付费用吗_百度知道
全民夺宝没有抢到需要支付费用吗
我有更好的答案
当然要支付费用
其他类似问题
为您推荐:
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁全民夺宝--一个无限惊喜的网站!
最近加入的奖品
您的清单中没有任何奖品
如果不能在帮助内容中找到答案,您还可以拨打:
400-998-6030
& 帮助中心
“全民夺宝”指用户花费1元购买“全民网盘” (/)1M空间后即可获赠1个夺宝币,用户可使用夺宝币参与奖品抽奖的服务。
奖品分配对应数量的号码,每个号码价值1个抢币,当一件奖品所有号码售出后,根据预先制定的规则计算出一个幸运号码,持有该号码的用户,直接获得该奖品。
&全民夺宝规则
获得抢币:用户花费1元购买全民夺宝网盘空间,即可获赠1个抢币
挑选喜欢的商品:奖品分配对应数量的号码,1个抢币可以获得其中1个号码(系统随机分配)
获得奖品:当所有号码都被分配完毕后,系统根据规则计算出1个幸运号码,持有该号码的用户,直接获得该奖品。
&幸运号码计算规则
截止该奖品开奖时间点前本站全部奖品的最后50参与时间所代表数值之和;
将这50个时间的数值进行求和(得出数值A)(每个时间按时、分、秒、毫秒的顺序组合,如20:15:25.123则为);
数值B为奖品所需人次;
数值A除以数值B得到的余数+原始数,得到最终幸运号码,拥有该幸运号码者,直接获得该奖品。
余数是指整数除法中被除数未被除尽部分, 如7÷3 = 2 ......1,1就是余数 。
温馨提示:消费者在娱乐同时,应该结合自身实际情况进行适当的消费。
客服热线:400-998-6030
微信公众号:qmdb369微信扫一扫
关注【遇事找法】随时随地获取法律帮助与生活法律热点常识
微信扫一扫关注
您当前位置:
&&&&&&&&&&&&&&&正文
请问 现在网上流行的
全民夺宝 一元淘
天天夺宝 是真实的吗?要绑定银行卡的! 谢谢
wl4173woil
请问 现在网上流行的
全民夺宝 一元淘
天天夺宝 是真实的吗?要绑定银行卡的! 谢谢
山东 泰安 发表时间: 19:42
微律云服务平台
温馨提示:只有认证通过的律师才能回复咨询。
遇到问题您可以尝试:
根据您遇到的问题找一个专业律师
网上银行卡
银行相关词条:
不用注册,快速回复,马上在线咨询专业律师!
您的问题描述越详细,律师回答越及时越准确~
律师回复后第一时间短信通知您
请输入正确的手机号码
验证码错误!
用户登录 |
记住登录状态
找法推荐律师
吉安优秀律师
相关法律帮助
Copyright@ 版权所有 找法网()- 中国大型法律服务平台&}

我要回帖

更多关于 全民夺宝骗局 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信