這篇文章將為大家詳細(xì)講解有關(guān)Android使用view實(shí)現(xiàn)倒計(jì)時控件,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。
直接上代碼
自定義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); //對文字只描邊 //設(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(); //兩個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)頁標(biāo)題:Android使用view實(shí)現(xiàn)倒計(jì)時控件-創(chuàng)新互聯(lián)
路徑分享:http://jinyejixie.com/article28/dieejp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開發(fā)、搜索引擎優(yōu)化、全網(wǎng)營銷推廣、網(wǎng)站設(shè)計(jì)公司、關(guān)鍵詞優(yōu)化、品牌網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容