当前位置: 首页 > news >正文

郑州网站推广策划网站访客qq获取

郑州网站推广策划,网站访客qq获取,杭州网站建设,网站的系统建设方式这篇文章主要介绍了Android秒杀倒计时自定义TextView示例#xff0c;大家参考使用吧 自定义TextView控件TimeTextView代码#xff1a; 复制代码 代码如下:import android.content.Context;import android.content.res.TypedArray;import android.graphics.Paint;import andro… 这篇文章主要介绍了Android秒杀倒计时自定义TextView示例大家参考使用吧 自定义TextView控件TimeTextView代码 复制代码 代码如下: import android.content.Context;import android.content.res.TypedArray;import android.graphics.Paint;import android.text.Html;import android.util.AttributeSet;import android.widget.TextView; import com.new0315.R;/** * 自定义倒计时文本控件 * author Administrator * */public class TimeTextView extends TextView implements Runnable{     Paint mPaint; //画笔,包含了画几何图形、文本等的样式和颜色信息     private long[] times;     private long mday, mhour, mmin, msecond;//天小时分钟秒     private boolean runfalse; //是否启动了     public TimeTextView(Context context, AttributeSet attrs) {        super(context, attrs);        mPaintnew Paint();        TypedArray array context.obtainStyledAttributes(attrs, R.styleable.TimeTextView);         array.recycle(); //一定要调用否则这次的设定会对下次的使用造成影响    }     public TimeTextView(Context context, AttributeSet attrs, int defStyle) {        super(context, attrs, defStyle);        mPaintnew Paint();        TypedArray array context.obtainStyledAttributes(attrs, R.styleable.TimeTextView);         array.recycle(); //一定要调用否则这次的设定会对下次的使用造成影响    }     public TimeTextView(Context context) {        super(context);    }     public long[] getTimes() {        return times;    }     public void setTimes(long[] times) {        this.times times;        mday times[0];        mhour times[1];        mmin times[2];        msecond times[3];     }     /**     * 倒计时计算     */    private void ComputeTime() {        msecond--;        if (msecond 0) {            mmin--;            msecond 59;            if (mmin 0) {                mmin 59;                mhour--;                if (mhour 0) {                    // 倒计时结束                    mhour 59;                    mday--;                 }            }         }     }     public boolean isRun() {        return run;    }     public void setRun(boolean run) {        this.run run;    }     Override    public void run() {        //标示已经启动        runtrue;         ComputeTime();         String strTime还剩/prespan stylecolor: red;mday/spanpre天/prespan stylecolor: red;mhour/spanpre小时/prespan stylecolor: red; mmin/spanpre分钟/prespan stylecolor: red;msecond/spanpre秒;        this.setText(Html.fromHtml(strTime));         postDelayed(this, 1000);     } } 属性atts.xml 复制代码 代码如下: declare-styleable nameTimeTextView/declare-styleable Adapter调用代码 复制代码 代码如下: import java.text.DecimalFormat;import java.util.List; import android.content.Context;import android.graphics.Paint;import android.util.Log;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.ImageView;import android.widget.LinearLayout;import android.widget.TextView; import com.new0315.R;import com.new0315.entity.SpecialGoods;import com.new0315.utils.CorrectSpecialDataFormHttp;import com.new0315.utils.DateTools;import com.new0315.widgets.TimeTextView;import com.nostra13.universalimageloader.core.ImageLoader; public class SpecialGoodsAdapter extends BaseAdapter {     private Context context;    private List list;    private long sumTime;     public SpecialGoodsAdapter(Context context) {         this.context context;    }     public void setList(List list) {        this.list list;    }     Override    public int getCount() {        // TODO Auto-generated method stub        return list.size();    }     Override    public Object getItem(int arg0) {        // TODO Auto-generated method stub        return null;    }     Override    public long getItemId(int arg0) {        // TODO Auto-generated method stub        return 0;    }     Override    public View getView(int arg0, View convertView, ViewGroup arg2) {        //开始计时性能测试用nanoTime会更精确因为它是纳秒级的        long startTime System.nanoTime();        Log.d(position,getView arg0 convertView);        ViewHolder viewHolder;        if(convertView null)        {            convertView LayoutInflater.from(context).inflate(                    R.layout.item_temai_list, null);            viewHolder new ViewHolder();            viewHolder.goodName (TextView) convertView                    .findViewById(R.id.temai_Name);            viewHolder.price (TextView) convertView                    .findViewById(R.id.temai_yuanjia_text);             viewHolder.specialPrice (TextView) convertView                    .findViewById(R.id.temai_xiajia_text);            //特卖倒计时控件            viewHolder.mTimeText (TimeTextView) convertView                    .findViewById(R.id.temai_timeTextView);             viewHolder.showDate (TextView) convertView                    .findViewById(R.id.index_temai_day);            viewHolder.showDate_l (LinearLayout) convertView                    .findViewById(R.id.temai_weikaishi);            viewHolder.showTime (LinearLayout) convertView                    .findViewById(R.id.temai_yikaishi);            viewHolder.koukou (TextView) convertView                    .findViewById(R.id.temai_zhekou_text);            viewHolder.image (ImageView) convertView                    .findViewById(R.id.index_temai_image);            Log.d(GoogleIO,new position:viewHolder.goodName.getText());             convertView.setTag(viewHolder);         }else {            viewHolder (ViewHolder) convertView.getTag();            resetViewHolder(viewHolder);        }        //setData        String off getOff(list.get(arg0).getGoods_Price(), list.get(arg0)                .getGoods_SpecialPrice());        viewHolder.goodName.setText(list.get(arg0).getGoods_Name());        viewHolder.price.setText(list.get(arg0).getGoods_Price());        viewHolder.price.getPaint().setFlags(                Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);        viewHolder.specialPrice.setText(list.get(arg0).getGoods_SpecialPrice());        viewHolder.koukou.setText(off 折);         if (DateTools.isStart(list.get(arg0).getSpecialFrom())) {            //特卖倒计时开始            viewHolder.mTimeText.setTimes(DateTools.getDate(CorrectSpecialDataFormHttp                    .correctData((list.get(arg0).getSpecialEnd()))));            //已经在倒计时的时候不再开启计时            if(!viewHolder.mTimeText.isRun())            {                viewHolder.mTimeText.run();            }            viewHolder.showDate_l.setVisibility(View.GONE);            viewHolder.showTime.setVisibility(View.VISIBLE);        } else {            viewHolder.showTime.setVisibility(View.GONE);            viewHolder.showDate_l.setVisibility(View.VISIBLE);            viewHolder.showDate.setText(DateTools.getDay(list.get(arg0).getSpecialFrom())                    );        }         ImageLoader.getInstance().displayImage(list.get(arg0).getGoods_Pic(),viewHolder.image);         //停止计时        long endTime System.nanoTime();        //耗时        long spendTime (endTime - startTime);         sumTime spendTime;//        Log.d(GoogleIO, position at:arg0--sumTime:String.valueOf(sumTime));        return convertView;    }     public String getOff(String price, String specialPrice) {         double off Double.parseDouble(specialPrice)                / Double.parseDouble(price) * 10;         DecimalFormat df new DecimalFormat(0.0);        String off_String df.format(off);         if (off_String.equals(NaN) || off_String.equals(1)) {            off_String 10;        }        return off_String;    }     static class ViewHolder {        ImageView image;        TextView goodName;        TextView price;        TextView specialPrice;        TextView koukou;        TimeTextView mTimeText;        TextView showDate;        LinearLayout showDate_l;        LinearLayout showTime;     }     protected void resetViewHolder(ViewHolder viewHolder) {        viewHolder.image.setImageBitmap(null);        viewHolder.goodName.setText();        viewHolder.price.setText();        viewHolder.specialPrice.setText();        viewHolder.koukou.setText();        viewHolder.mTimeText.setText();        viewHolder.showDate.setText();     }} layout使用代码 复制代码 代码如下: LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:backgrounddrawable/home_panicbuying_backgroundandroid:orientationvertical !-- 免单 -- RelativeLayoutandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:layout_marginTop5dp FrameLayoutandroid:idid/index_temai_image_layoutandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_centerVerticaltrueandroid:layout_margin5dp ImageViewandroid:idid/index_temai_imageandroid:layout_width80dpandroid:layout_height80dp / ImageViewandroid:idid/index_temai_discount_iconandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_gravitytop|leftandroid:backgrounddrawable/app_limit_buy_saleandroid:srcdrawable/app_limit_buy_begin //FrameLayout LinearLayoutandroid:idid/temai_date_showandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_toRightOfid/index_temai_image_layoutandroid:orientationvertical RelativeLayoutandroid:layout_widthwrap_contentandroid:layout_heightwrap_content LinearLayoutandroid:idid/temai_weikaishiandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_marginTop2dpandroid:orientationhorizontal TextViewandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text距离开始还有android:textColorcolor/blackandroid:textSizedimen/small_text_sizeandroid:textStylebold / TextViewandroid:idid/index_temai_dayandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text99android:textColorcolor/redandroid:textSizedimen/small_text_sizeandroid:textStylebold / TextViewandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text天android:textColorcolor/blackandroid:textSizedimen/small_text_sizeandroid:textStylebold //LinearLayout LinearLayoutandroid:idid/temai_yikaishiandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_marginTop2dpandroid:orientationhorizontal com.new0315.widgets.TimeTextViewandroid:idid/temai_timeTextViewandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:textColorandroid:color/blackandroid:textSizedimen/small_text_size/ /LinearLayout/RelativeLayout LinearLayoutandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_marginBottom5dpandroid:layout_marginRight20dpandroid:layout_marginTop5dpandroid:orientationhorizontal TextViewandroid:idid/temai_Nameandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:lines2android:text大众甲壳虫豪华款曾全套汽车配件十年加油卡车库补贴十年车险五年以旧换新服务比提供五年免费待架服务android:textColorcolor/blackandroid:textSize12sp //LinearLayout LinearLayoutandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:orientationhorizontal TextViewandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:textstring/index_raw_priceandroid:textColorcolor/darkgrayandroid:textSizedimen/small_text_size / TextViewandroid:idid/temai_yuanjia_textandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_marginLeft5dpandroid:textColorcolor/darkgrayandroid:textSizedimen/small_text_size //LinearLayout/LinearLayout/RelativeLayout LinearLayoutandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_margin5spandroid:backgrounddrawable/app_limit_buy_sale_bgandroid:gravitycenter_vertical LinearLayoutandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_marginLeft30dpandroid:layout_marginTop3dpandroid:orientationhorizontal TextViewandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text特卖价android:textColor#919263android:textSize13sp / TextViewandroid:idid/temai_xiajia_textandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_marginLeft5dpandroid:layout_marginRight5spandroid:text400android:textColorcolor/redandroid:textSize13sp / TextViewandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text折扣android:textColor#919263android:textSize13sp / TextViewandroid:idid/temai_zhekou_textandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_marginLeft5dpandroid:layout_marginRight5spandroid:text5.0折android:textColorcolor/greenandroid:textSize13sp //LinearLayout/LinearLayout /LinearLayout   转载于:https://www.cnblogs.com/Free-Thinker/p/3938451.html
http://www.pierceye.com/news/59137/

相关文章:

  • vs2008不能新建网站制作一个完整的网页的步骤
  • seo快速排名网站优化二手房装修
  • 网站建设公司业务提成多少特色的网站建设
  • 自己做网站新手入门安徽城乡建设 厅网站
  • 做一万个网站南郑县城乡建设局网站
  • 建设高校实验室教学网站的作用郴州新网交友
  • 机关 网站 建设方案法与家国建设征文网站
  • 做网站的要多少钱wordpress 用什么编辑器
  • 多国语言网站网站设计 网络推广的服务内容
  • 搜索引擎网站的结构买卖交易网
  • 自己做的视频可以同时上传到几家网站百度seo多久能优化关键词
  • 小x导航正品海口seo关键词优化
  • 网站转发wordpress中文版广告
  • 广州网站建设 讯度网络长沙网上房地产
  • h5网站动画怎么做为什么做彩票网站会被提示危险
  • 建设网站要点emloh转wordpress
  • 软件开发还是网站开发好做拍卖网站需要多少钱
  • 做a的视频在线观看网站wplounge wordpress主题
  • 网站建设方案设计心得泉州教育网站
  • 网站建设图片编辑浦口区网站建设
  • 做公众号链接的网站百度明令禁止搜索的词
  • 小吃店网站建设全国信用信息公示系统官网
  • yu网站建设哪里有做证
  • 黄岩做网站公司电话做网店运营新手入门教程
  • 如何做网站营销wordpress站点如何适应手机
  • 招聘网站怎么做介绍如何自学做网站
  • 17网一起做网店网站音箱厂家东莞网站建设
  • python网站开发快吗外包公司是做什么的
  • 网址和网站的区别怎么发现网站漏洞而做软件
  • wordpress自定义链接百度seo软件优化