Android高级UI ProgressBar实现各种效果的圆形进度

这篇博客介绍了如何在Android中创建不同大小的圆形进度条以及水平进度条。内容涵盖了命名空间的概念,提供了布局设计和对应的Java代码示例。
部署运行你感兴趣的模型镜像

内容

包含小、中、大的圆形进度条
包含水平进度条

什么是命名空间?

Android的xmlns,这个是XML Namespaces的缩写,中文名称是XML(标准通用标记语言的子集)命名空间
链接:http://blog.sina.com.cn/s/blog_a28e3dd90102uxmc.html

布局

依次为:
圆形进度条:小
圆形进度条:中
圆形进度条:大
水平进度条:一级进度条
水平进度条:二级进度条
二级进度条控制按钮

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.feather.androiddemos.ProgressBarActivity">

    <ProgressBar
        style="?android:attr/progressBarStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <ProgressBar
        style="?android:attr/progressBarStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <ProgressBar
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <ProgressBar
        android:id="@+id/progress_one_level_bar"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="100pt"
        android:layout_height="wrap_content"
        android:max="100"
        android:progress="30" />

    <!--max为最大进度,progress为当前一级进度,secondaryProgress为当前二级进度-->
    <ProgressBar
        android:id="@+id/progress_two_level_bar"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="100pt"
        android:layout_height="wrap_content"
        android:max="100"
        android:progress="30"
        android:secondaryProgress="50" />

    <Button
        android:id="@+id/progress_one_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="单级进度条" />

    <Button
        android:id="@+id/progress_two_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="二级进度条" />

</LinearLayout>

Java代码

public class ProgressBarActivity extends AppCompatActivity {

    Button oneButton;
    Button twoButton;
    ProgressBar progressBar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_progress_bar);

        oneButton = (Button) findViewById(R.id.progress_one_button); //增加进度按钮
        twoButton = (Button) findViewById(R.id.progress_two_button); //减少进度按钮
        progressBar = (ProgressBar) findViewById(R.id.progress_two_level_bar); //二级进度条

        oneButton.setOnClickListener(new buttonListenner()); //设置监听器
        twoButton.setOnClickListener(new buttonListenner());
    }

    class buttonListenner implements View.OnClickListener{

        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.progress_one_button:               //增加一级和二级进度条
                    progressBar.incrementProgressBy(10);
                    progressBar.incrementSecondaryProgressBy(10);

                    break;
                case R.id.progress_two_button:               //减少进度条
                    progressBar.incrementProgressBy(-10);
                    progressBar.incrementSecondaryProgressBy(-10);

                    break;
            }
        }
    }

}

您可能感兴趣的与本文相关的镜像

ACE-Step

ACE-Step

音乐合成
ACE-Step

ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

猎羽

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值