Android使用view實(shí)現(xiàn)倒計(jì)時(shí)控件-創(chuàng)新互聯(lián)

這篇文章將為大家詳細(xì)講解有關(guān)Android使用view實(shí)現(xiàn)倒計(jì)時(shí)控件,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。

公司主營(yíng)業(yè)務(wù):網(wǎng)站設(shè)計(jì)制作、成都網(wǎng)站設(shè)計(jì)、移動(dòng)網(wǎng)站開(kāi)發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實(shí)現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競(jìng)爭(zhēng)能力。成都創(chuàng)新互聯(lián)是一支青春激揚(yáng)、勤奮敬業(yè)、活力青春激揚(yáng)、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊(duì)。公司秉承以“開(kāi)放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對(duì)我們的高要求,感謝他們從不同領(lǐng)域給我們帶來(lái)的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會(huì)用頭腦與智慧不斷的給客戶帶來(lái)驚喜。成都創(chuàng)新互聯(lián)推出裕民免費(fèi)做網(wǎng)站回饋大家。

Android使用view實(shí)現(xiàn)倒計(jì)時(shí)控件

Android使用view實(shí)現(xiàn)倒計(jì)時(shí)控件

直接上代碼

自定義TextView

文字展示

public class StrokeTextView extends TextView {

 private TextView borderText = null;///用于描邊的TextView
 private Context mContext;

 public StrokeTextView(Context context) {
  super(context);
  mContext = context;
  borderText = new TextView(context);
  init();
 }

 public StrokeTextView(Context context, AttributeSet attrs) {
  super(context, attrs);
  mContext = context;
  borderText = new TextView(context, attrs);
  init();
 }

 public StrokeTextView(Context context, AttributeSet attrs, int defStyle) {
  super(context, attrs, defStyle);
  mContext = context;
  borderText = new TextView(context, attrs, defStyle);
  init();
 }

 public void init() {
  TextPaint tp1 = borderText.getPaint();
  tp1.setStrokeWidth(12);         //設(shè)置描邊寬度
  tp1.setStyle(Paint.Style.STROKE);        //對(duì)文字只描邊
  //設(shè)置自定義字體
  Typeface fromAsset = Typeface.createFromAsset(mContext.getAssets(), "fonts/Alibaba-PuHuiTi-Heavy.ttf");
  borderText.setTypeface(fromAsset, Typeface.ITALIC); //自定義字體 ITALIC斜體
  borderText.setTextColor(Color.parseColor("#F46059")); //設(shè)置描邊顏色
  borderText.setShadowLayer(3.0F, 2F, 2F, Color.parseColor("#ffd44042")); //設(shè)置陰影效果(投影)
  borderText.setGravity(getGravity());
 }

 @Override
 public void setLayoutParams(ViewGroup.LayoutParams params) {
  super.setLayoutParams(params);
  borderText.setLayoutParams(params);
 }

 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  CharSequence tt = borderText.getText();

  //兩個(gè)TextView上的文字必須一致
  if (tt == null || !tt.equals(this.getText())) {
   borderText.setText(getText());
   this.postInvalidate();
  }
  super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  borderText.measure(widthMeasureSpec, heightMeasureSpec);
 }

 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
  super.onLayout(changed, left, top, right, bottom);
  borderText.layout(left, top, right, bottom);
 }

 @Override
 protected void onDraw(Canvas canvas) {
  borderText.draw(canvas);
  super.onDraw(canvas);
 }

}

網(wǎng)頁(yè)標(biāo)題:Android使用view實(shí)現(xiàn)倒計(jì)時(shí)控件-創(chuàng)新互聯(lián)
路徑分享:http://muchs.cn/article28/dieejp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開(kāi)發(fā)、搜索引擎優(yōu)化、全網(wǎng)營(yíng)銷(xiāo)推廣、網(wǎng)站設(shè)計(jì)公司關(guān)鍵詞優(yōu)化、品牌網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁(yè)設(shè)計(jì)公司