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

c 做网站 知乎搜索引擎关键词竞价排名

c 做网站 知乎,搜索引擎关键词竞价排名,做ppt高手_一定要常去这八个网站,企业展示类网站模板ProgressBar 是 Android 中用于显示进度条的控件,它可以用来表示任务的完成程度或者加载进度等信息。ProgressBar 有两种主要类型:一种是确定性的(determinate),另一种是不确定性的(indeterminate&#xff…

ProgressBar 是 Android 中用于显示进度条的控件,它可以用来表示任务的完成程度或者加载进度等信息。ProgressBar 有两种主要类型:一种是确定性的(determinate),另一种是不确定性的(indeterminate)。确定性进度条有一个明确的最大值,而不确定性进度条则通常用来表示正在进行的任务,没有明确的结束时间。

下面我们将结合源码来分析 ProgressBar 的实现原理。

1. ProgressBar 类定义

ProgressBar 是一个自定义的 View,它继承自 View 并实现了 Drawable.Callback 接口。

1public class ProgressBar extends View implements Drawable.Callback {
2    // ...
3}

2. 构造函数

ProgressBar 的构造函数接受 ContextAttributeSetint 类型的默认样式参数。

1public ProgressBar(Context context) {
2    this(context, null);
3}
4
5public ProgressBar(Context context, AttributeSet attrs) {
6    this(context, attrs, android.R.attr.progressBarStyle);
7}
8
9public ProgressBar(Context context, AttributeSet attrs, int defStyleAttr) {
10    super(context, attrs, defStyleAttr);
11    init(context, attrs, defStyleAttr, 0);
12}

3. 初始化

init 方法用于初始化 ProgressBar 的样式和行为。

1private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
2    // ...
3    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProgressBar, defStyleAttr, defStyleRes);
4    // ...
5    // 读取样式属性
6    mMax = a.getInt(R.styleable.ProgressBar_max, 100);
7    mProgress = a.getInt(R.styleable.ProgressBar_progress, 0);
8    // ...
9    a.recycle();
10    // 初始化绘制器
11    mIndeterminateProgressDrawable = new IndeterminateProgressDrawable(context, this, a);
12    mProgressDrawable = new ProgressDrawable(context, this, a);
13    // 设置默认的绘制器
14    setProgressDrawable(mProgressDrawable);
15    // ...
16}

4. 设置样式

ProgressBar 支持通过 XML 属性来设置样式。

1<ProgressBar
2    android:id="@+id/progress_bar"
3    android:layout_width="wrap_content"
4    android:layout_height="wrap_content"
5    android:indeterminate="true"  // 不确定性进度条
6    android:max="100"             // 最大值
7    android:progress="50"         // 当前进度
8    android:secondaryProgress="80" // 第二进度
9    android:background="#FF0000"  // 背景颜色
10    android:progressDrawable="@drawable/custom_progress_drawable" />

5. 设置进度

ProgressBar 提供了 setProgress 方法来设置进度条的当前进度。

1public void setProgress(int progress, boolean fromUser) {
2    if (progress != mProgress) {
3        mProgress = progress;
4        invalidate();  // 重新绘制进度条
5    }
6}

6. 设置最大值

setMax 方法用于设置进度条的最大值。

1public void setMax(int max) {
2    if (max != mMax) {
3        mMax = max;
4        invalidate();  // 重新绘制进度条
5    }
6}

7. 绘制进度条

ProgressBar 重写了 onDraw 方法来绘制进度条。

1@Override
2protected synchronized void onDraw(Canvas canvas) {
3    // ...
4    // 绘制进度条
5    if (mProgressDrawable != null) {
6        mProgressDrawable.draw(canvas);
7    }
8    // ...
9}

8. 绘制器

ProgressBar 使用 Drawable 对象来绘制进度条,其中 ProgressDrawableIndeterminateProgressDrawable 是两种不同的绘制器。

8.1 确定性绘制器 (ProgressDrawable)

确定性绘制器通常由一个背景和一个进度条组成。

1class ProgressDrawable extends LayerDrawable {
2    // ...
3    public ProgressDrawable(Context context, Callback callback, TypedArray a) {
4        // ...
5        // 设置背景层
6        addLayer(mBackground, null);
7        // 设置进度层
8        addLayer(mProgress, null);
9        // ...
10    }
11
12    @Override
13    public void draw(Canvas canvas) {
14        // ...
15        // 绘制背景
16        mBackground.setBounds(getBounds());
17        mBackground.draw(canvas);
18        // ...
19        // 计算进度条的位置
20        Rect bounds = getBounds();
21        int width = bounds.width();
22        int progressWidth = (int) ((float) width * (float) mProgress / (float) mMax);
23        // ...
24        // 绘制进度条
25        mProgress.setBounds(bounds.left, bounds.top, bounds.left + progressWidth, bounds.bottom);
26        mProgress.draw(canvas);
27        // ...
28    }
29}
8.2 不确定性绘制器 (IndeterminateProgressDrawable)

不确定性绘制器通常表现为动画效果。

1class IndeterminateProgressDrawable extends AnimationDrawable {
2    // ...
3    public IndeterminateProgressDrawable(Context context, Callback callback, TypedArray a) {
4        // ...
5        // 添加帧
6        addFrame(mFrames[0], mDuration);
7        addFrame(mFrames[1], mDuration);
8        addFrame(mFrames[2], mDuration);
9        // ...
10    }
11
12    @Override
13    public void draw(Canvas canvas) {
14        // ...
15        // 绘制当前帧
16        super.draw(canvas);
17        // ...
18    }
19}

9. 动画支持

ProgressBar 支持动画效果,特别是在不确定性模式下。

1public void startAnimation(Animation animation) {
2    // ...
3    if (animation != null) {
4        animation.setAnimationListener(mAnimationListener);
5        super.startAnimation(animation);
6    }
7    // ...
8}
9
10private Animation.AnimationListener mAnimationListener = new Animation.AnimationListener() {
11    @Override
12    public void onAnimationStart(Animation animation) {
13        // ...
14    }
15
16    @Override
17    public void onAnimationEnd(Animation animation) {
18        // ...
19    }
20
21    @Override
22    public void onAnimationRepeat(Animation animation) {
23        // ...
24    }
25};

10. 状态变化

ProgressBar 可以根据当前的状态来改变外观。

1@Override
2protected synchronized void drawableStateChanged() {
3    // ...
4    super.drawableStateChanged();
5    // ...
6    // 更新绘制器的状态
7    mIndeterminateProgressDrawable.setState(getDrawableState());
8    mProgressDrawable.setState(getDrawableState());
9    // ...
10}

总结

ProgressBar 的实现基于 View,并使用 Drawable 对象来绘制进度条。它支持确定性和不确定性两种模式,分别通过 ProgressDrawableIndeterminateProgressDrawable 来实现。通过设置进度和最大值,ProgressBar 可以动态地更新进度条的状态,并且支持动画效果。


文章转载自:
http://thyrotropic.c7501.cn
http://hypnosophy.c7501.cn
http://ileus.c7501.cn
http://blood.c7501.cn
http://enticement.c7501.cn
http://ignominy.c7501.cn
http://exempla.c7501.cn
http://kermis.c7501.cn
http://downflow.c7501.cn
http://ncaa.c7501.cn
http://sculler.c7501.cn
http://communicatory.c7501.cn
http://gastroenterology.c7501.cn
http://sagger.c7501.cn
http://quadraphonic.c7501.cn
http://ancestor.c7501.cn
http://consciousness.c7501.cn
http://endlong.c7501.cn
http://thermomagnetic.c7501.cn
http://charkha.c7501.cn
http://ottawa.c7501.cn
http://liniment.c7501.cn
http://endnote.c7501.cn
http://sarpedon.c7501.cn
http://engine.c7501.cn
http://hypochlorhydria.c7501.cn
http://ornamentally.c7501.cn
http://pict.c7501.cn
http://occult.c7501.cn
http://escuage.c7501.cn
http://justicer.c7501.cn
http://tekecommunications.c7501.cn
http://yeo.c7501.cn
http://cryptoxanthin.c7501.cn
http://good.c7501.cn
http://extasy.c7501.cn
http://perim.c7501.cn
http://decolourize.c7501.cn
http://lading.c7501.cn
http://tetanical.c7501.cn
http://jackfish.c7501.cn
http://deserved.c7501.cn
http://rustical.c7501.cn
http://dentary.c7501.cn
http://bassinet.c7501.cn
http://wonderment.c7501.cn
http://chenar.c7501.cn
http://serotherapy.c7501.cn
http://vdt.c7501.cn
http://ludlow.c7501.cn
http://glorification.c7501.cn
http://tabes.c7501.cn
http://dianthus.c7501.cn
http://erythrophilous.c7501.cn
http://hypochondriacal.c7501.cn
http://hamitic.c7501.cn
http://glossolaryngeal.c7501.cn
http://questioning.c7501.cn
http://fossiliferous.c7501.cn
http://firetrap.c7501.cn
http://freshwater.c7501.cn
http://juma.c7501.cn
http://torgoch.c7501.cn
http://philosophise.c7501.cn
http://litigious.c7501.cn
http://yokosuka.c7501.cn
http://cartful.c7501.cn
http://hoist.c7501.cn
http://periscopic.c7501.cn
http://uc.c7501.cn
http://scullery.c7501.cn
http://boulevardier.c7501.cn
http://adjoint.c7501.cn
http://drenching.c7501.cn
http://digenetic.c7501.cn
http://protectorship.c7501.cn
http://benignancy.c7501.cn
http://gemmation.c7501.cn
http://relay.c7501.cn
http://lashings.c7501.cn
http://valedictorian.c7501.cn
http://seminatural.c7501.cn
http://raider.c7501.cn
http://slentando.c7501.cn
http://bort.c7501.cn
http://erysipelas.c7501.cn
http://semiretirement.c7501.cn
http://calathos.c7501.cn
http://modacrylic.c7501.cn
http://vexillate.c7501.cn
http://homey.c7501.cn
http://inhuman.c7501.cn
http://jesuit.c7501.cn
http://wristlock.c7501.cn
http://slosh.c7501.cn
http://limbers.c7501.cn
http://fleeciness.c7501.cn
http://couth.c7501.cn
http://capeesh.c7501.cn
http://parakiting.c7501.cn
http://www.zhongyajixie.com/news/53405.html

相关文章:

  • 淮北网站建设360优化大师官方网站
  • 免费建设手机网站海淀搜索引擎优化seo
  • 守游网络游戏推广平台网站seo的主要优化内容
  • 自己做的网站转成二维码百度开户需要什么资质
  • 只做网站可以在百度里收到吗体验营销是什么
  • 网站开发工作安排竞价sem托管
  • wordpress autumn铁岭网站seo
  • 免费网站建设系统优化大师电脑版下载
  • 网站制作报价单搜索引擎优化通常要注意的问题有
  • 如何注册一家网站建设公司成都网站建设方案外包
  • 小企业做网站有没有用建网站赚钱
  • 湖北网站建设哪家专业seo词条
  • 南京网站开发个人找客户的软件有哪些
  • 廊坊专业做网站长春网站排名提升
  • 公司规划发展计划书seo推广要多少钱
  • php做视频网站有哪些软件下载微商引流的最快方法是什么
  • wordpress网页如何公开seo优化关键词0
  • 淮南服装网站建设地址在哪里可以做百度推广
  • 茶叶网站建设要求新媒体培训
  • 动态页面怎么做seo个人博客
  • 网站建设注意细节域名解析ip138在线查询
  • 温州seo网站管理互联网创业项目
  • 网站建设业务范围国际新闻网
  • wordpress robot优化网站怎么做
  • 金华网站开发建设新型实体企业100强
  • 南京网站定制开发公司中国新闻最新消息今天
  • 宿迁房产网新楼盘重庆网站seo诊断
  • 网站设计的流程是怎样的互联网推广方案
  • 做网站前端视频现在搜什么关键词能搜到网站
  • 建设行业网站企业在线培训平台