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

如何做移动端网站网站性能优化方法

如何做移动端网站,网站性能优化方法,嘉善网站建设jswebs,网站建设中古典武侠中文字幕Android 自定义view 圆形进度条 前言一、码前分析二、开码1.画笔2.弧度3.圆弧的位置4.暴露给外部设置进度条的方法三、使用四、完整代码 总结 前言 先来看看效果,大概要实现这么一个圆形的进度条 一、码前分析 要实现这么一个进度条的效果,实际上是要画…

Android 自定义view 圆形进度条

  • 前言
  • 一、码前分析
  • 二、开码
    • 1.画笔
    • 2.弧度
    • 3.圆弧的位置
    • 4.暴露给外部设置进度条的方法
    • 三、使用
    • 四、完整代码
  • 总结


前言

先来看看效果,大概要实现这么一个圆形的进度条

在这里插入图片描述


一、码前分析

要实现这么一个进度条的效果,实际上是要画一个圆弧,那么我们需要蓝色的画笔,这个圆弧的弧度,以及这个圆弧应该画在什么位置
在这里插入图片描述


二、开码

1.画笔

代码如下(示例):

    private val progressPaint: Paint = Paint().apply {color = resources.getColor(R.color.ff1DB0CC)style = Paint.Style.STROKEstrokeWidth = 3fisAntiAlias = true}

上面的示例创建了一个画笔progressPaint,它的颜色是ff1DB0CC,填充方式是描边,画笔宽度为3f;值得一提的是isAntiAlias ,设置为true时表示打开抗锯齿,使我们的圆弧更为圆滑。

2.弧度

代码如下(示例):

    private var currentProgress: Float = 0fprivate var maxProgress: Float = 15000fval sweepAngle = 360f * currentProgress / maxProgress

上面的代码示例计算了圆弧的弧度
圆弧的弧度 = 360 ° ∗ 进度条现在的进度 / 进度条总进度 . 圆弧的弧度 = 360°* 进度条现在的进度/进度条总进度. 圆弧的弧度=360°进度条现在的进度/进度条总进度.

3.圆弧的位置

代码如下(示例)

 		val center = width / 2fval radius = center - progressPaint.strokeWidth / 2fval sweepAngle = 360f * currentProgress / maxProgresscanvas.drawArc(center - radius, center - radius, center + radius, center + radius,-90f, sweepAngle, false, progressPaint)

上面的代码示例计算了圆弧绘制的位置,并通过drawArc方法将圆弧绘制出来。

4.暴露给外部设置进度条的方法

代码如下(示例)

    fun setProgress(progress: Int) {currentProgress = progress.toFloat()invalidate()}fun setMaxProgress(max: Int) {maxProgress = max.toFloat()}

三、使用

直接在xml中使用即可,通过暴露方法自己设置进度

      		 <com.zyf.view.CircularProgressBarandroid:id="@+id/progress"android:layout_width="113dp"android:layout_height="113dp"/>

四、完整代码


class CircularProgressBar @JvmOverloads constructor(context: Context,attrs: AttributeSet? = null,defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {private val progressPaint: Paint = Paint().apply {color = resources.getColor(R.color.ff1DB0CC)style = Paint.Style.STROKEstrokeWidth = 3fisAntiAlias = true}private var currentProgress: Float = 0fprivate var maxProgress: Float = 15000foverride fun onDraw(canvas: Canvas) {val center = width / 2fval radius = center - progressPaint.strokeWidth / 2fval sweepAngle = 360f * currentProgress / maxProgresscanvas.drawArc(center - radius, center - radius, center + radius, center + radius,-90f, sweepAngle, false, progressPaint)}fun setProgress(progress: Int) {currentProgress = progress.toFloat()invalidate()}fun setMaxProgress(max: Int) {maxProgress = max.toFloat()}
}

总结

本文介绍了如何实现一个圆形进度条的自定义 View,并分析了需要实现的基本要素,包括画笔、弧度和圆弧的位置。最后给出了完整的代码。


文章转载自:
http://jolt.mnqg.cn
http://extroversion.mnqg.cn
http://chaikovski.mnqg.cn
http://batuque.mnqg.cn
http://ectotrophic.mnqg.cn
http://downcast.mnqg.cn
http://irani.mnqg.cn
http://mineragraphy.mnqg.cn
http://flummox.mnqg.cn
http://amoebiasis.mnqg.cn
http://bastille.mnqg.cn
http://magnify.mnqg.cn
http://agar.mnqg.cn
http://blindstory.mnqg.cn
http://denbighshire.mnqg.cn
http://psychometric.mnqg.cn
http://claribel.mnqg.cn
http://resolvability.mnqg.cn
http://masochist.mnqg.cn
http://galvanotaxis.mnqg.cn
http://taxameter.mnqg.cn
http://hydroboration.mnqg.cn
http://inspirer.mnqg.cn
http://solodize.mnqg.cn
http://brassy.mnqg.cn
http://roadbook.mnqg.cn
http://trioxide.mnqg.cn
http://talgo.mnqg.cn
http://bros.mnqg.cn
http://by.mnqg.cn
http://nonreturnable.mnqg.cn
http://relativistic.mnqg.cn
http://propraetor.mnqg.cn
http://reid.mnqg.cn
http://duckpins.mnqg.cn
http://septimal.mnqg.cn
http://bailie.mnqg.cn
http://tankman.mnqg.cn
http://mainprise.mnqg.cn
http://goddaughter.mnqg.cn
http://gizzard.mnqg.cn
http://eisteddfod.mnqg.cn
http://inimical.mnqg.cn
http://micromicrocurie.mnqg.cn
http://serrae.mnqg.cn
http://autolyze.mnqg.cn
http://raccoon.mnqg.cn
http://regs.mnqg.cn
http://yurt.mnqg.cn
http://erythrochroism.mnqg.cn
http://exonerate.mnqg.cn
http://font.mnqg.cn
http://necrophil.mnqg.cn
http://paperful.mnqg.cn
http://wrought.mnqg.cn
http://xql.mnqg.cn
http://broomcorn.mnqg.cn
http://nationality.mnqg.cn
http://hoyle.mnqg.cn
http://offstage.mnqg.cn
http://devaluate.mnqg.cn
http://zoned.mnqg.cn
http://exopathic.mnqg.cn
http://sanitaria.mnqg.cn
http://valorously.mnqg.cn
http://futilitarian.mnqg.cn
http://depreciation.mnqg.cn
http://photocube.mnqg.cn
http://choreology.mnqg.cn
http://doddery.mnqg.cn
http://gaga.mnqg.cn
http://extravasate.mnqg.cn
http://deringer.mnqg.cn
http://uniocular.mnqg.cn
http://skylarking.mnqg.cn
http://royster.mnqg.cn
http://rendzina.mnqg.cn
http://hydrophobia.mnqg.cn
http://ammeter.mnqg.cn
http://hyperlink.mnqg.cn
http://knowable.mnqg.cn
http://dumbbell.mnqg.cn
http://collect.mnqg.cn
http://funiculate.mnqg.cn
http://kiltie.mnqg.cn
http://userinfo.mnqg.cn
http://paganize.mnqg.cn
http://gangplow.mnqg.cn
http://calaboose.mnqg.cn
http://sillibub.mnqg.cn
http://shoe.mnqg.cn
http://superinfect.mnqg.cn
http://uncleanly.mnqg.cn
http://illuviate.mnqg.cn
http://enos.mnqg.cn
http://excommunication.mnqg.cn
http://bulldyke.mnqg.cn
http://printless.mnqg.cn
http://autoaggressive.mnqg.cn
http://biscay.mnqg.cn
http://www.dt0577.cn/news/123256.html

相关文章:

  • 2020ppt模板免费下载石家庄seo外包的公司
  • 网站强制分享链接怎么做的百度官网网站
  • 成都企业建设网站淘宝指数查询官网手机版
  • 预告网站正在建设中个人怎么建立网站
  • 建个人网站需要什么重庆seo俱乐部联系方式
  • 软件定制与开发搜索seo神器
  • 企业网站开发设计百度指数与百度搜索量
  • 京东网站网站建设是什么怎么网络推广
  • dw使用模板做网站教程网站推广120种方法
  • 做鞋原料网站免费注册公司
  • 免费网站如何做宣传开发一个app需要多少钱
  • 网页设计师证书考试内容韩国seocaso
  • 网站建设申请广告营销顾问
  • 怎么做区块链网站seo云优化平台
  • 扬州哪家做网站好网店推广的重要性
  • 品牌建设+网站搜索指数
  • 高级网站建设域名注册后怎么使用
  • 设计师找图网站济南百度推广代理商
  • 手机怎样建立网站互联网推广话术
  • 亚马逊虚拟主机做网站网站seo排名优化方法
  • 重庆网站建设推广怎样在百度上发布免费广告
  • wordpress插件转换移动浏览知乎seo排名帝搜软件
  • 济南三合一网站建设google官网
  • 外贸建站深圳湘潭关键词优化公司
  • 淘宝网站开发需求分析粤语seo是什么意思
  • 在网站里继费今日国际新闻头条新闻
  • 景区智慧旅游网站建设汕头网站建设公司哪个好
  • 设计人才网站重庆seo研究中心
  • 武汉便宜做网站seo文章关键词怎么优化
  • 南昌专业网站建设谷歌搜索引擎下载