Android使用view实现倒计时控件-创新互联
这篇文章将为大家详细讲解有关Android使用view实现倒计时控件,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
公司主营业务:网站设计制作、成都网站设计、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。成都创新互联是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。成都创新互联推出裕民免费做网站回馈大家。直接上代码
自定义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); //设置描边宽度 tp1.setStyle(Paint.Style.STROKE); //对文字只描边 //设置自定义字体 Typeface fromAsset = Typeface.createFromAsset(mContext.getAssets(), "fonts/Alibaba-PuHuiTi-Heavy.ttf"); borderText.setTypeface(fromAsset, Typeface.ITALIC); //自定义字体 ITALIC斜体 borderText.setTextColor(Color.parseColor("#F46059")); //设置描边颜色 borderText.setShadowLayer(3.0F, 2F, 2F, Color.parseColor("#ffd44042")); //设置阴影效果(投影) 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); } }
本文名称:Android使用view实现倒计时控件-创新互联
当前链接:http://scyanting.com/article/dieejp.html