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

内容

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

什么是命名空间?

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

布局

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


<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" />

    
    <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;
            }
        }
    }

}

你可能感兴趣的:(Android,android)