码迷,mamicode.com
首页 > 其他好文 > 详细

ProgressBar 系统进度条【案例】

时间:2017-02-21 17:33:54      阅读:365      评论:0      收藏:0      [点我收藏+]

标签:风格   order   encoding   over   idt   技术   public   不显示   color   

技术分享

布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal" >
        <!-- 1、默认风格progressBarStyle,中号圆形,表示一个过程正在执行中,默认风格为:圆形的、中等大小的、一直旋转的、不确定的进度条 -->
        <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <!-- 2、自定义大小。indeterminateTint:不确定进度条的着色。indeterminateTintMode:颜色混合模式 -->
        <ProgressBar
            style="?android:attr/progressBarStyleInverse"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:indeterminateTint="#f00"
            android:indeterminateTintMode="src_in" />
        <!-- 3、indeterminateDuration:动画的持续时间(不知道怎么用)。对不确定进度条设置进度相关的属性都是无效的。 -->
        <ProgressBar
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:indeterminateDuration="500"
            android:indeterminateTint="#00f"
            android:indeterminateTintMode="src_over" />
        <!-- 4、大号圆形。indeterminateDrawable:不确定样式图片。indeterminateBehavior:循环模式。interpolator:加速模式 -->
        <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:indeterminateBehavior="cycle"
            android:indeterminateDrawable="@drawable/rotate_image"
            android:indeterminateTint="#f00"
            android:indeterminateTintMode="multiply"
            android:interpolator="@android:anim/accelerate_interpolator" />
        <ProgressBar
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:indeterminateDrawable="@drawable/rotate_shape"
            android:interpolator="@android:anim/decelerate_interpolator" />
    </LinearLayout>
    <!-- ===========================水平进度条 progressBarStyleHorizontal=========================== -->
    <ProgressBar
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <!-- indeterminate:是否允许使用不确定模式。indeterminate或indeterminateOnly有一个属性为true则不显示具体的进度 -->
    <ProgressBar
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:indeterminate="false"
        android:indeterminateOnly="true" />
    <!-- 不确定模式下要使用indeterminateDrawable,确定模式下使用progressDrawable -->
    <ProgressBar
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:indeterminate="true"
        android:indeterminateDrawable="@android:drawable/progress_indeterminate_horizontal"
        android:indeterminateOnly="true" />
    <!-- 也可以将不确定模式进度条的indeterminateDrawable设置为确定模式进度条的progressDrawable -->
    <ProgressBar
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:indeterminate="true"
        android:indeterminateDrawable="@drawable/progress_drawable" />
    <ProgressBar
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:layout_marginTop="10dp"
        android:indeterminate="true"
        android:indeterminateDrawable="@drawable/progress_drawable" />
    <!-- 设置progressDrawable之后,将无法区分progress和secondaryProgress,显示的进度将直接是secondaryProgress -->
    <ProgressBar
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="5dp"
        android:layout_marginTop="10dp"
        android:progress="20"
        android:progressDrawable="@drawable/progress_drawable"
        android:secondaryProgress="50" />
    <!-- progressTint:进度条的颜色。secondaryProgressTint:第二进度条的颜色 -->
    <ProgressBar
        android:id="@+id/pb"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:max="100"
        android:progress="50"
        android:progressTint="#00f"
        android:secondaryProgress="60"
        android:secondaryProgressTint="#f00" />
    <ProgressBar
        android:id="@+id/pb1"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

不确定样式进度-1

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <rotate
            android:drawable="@drawable/ic_launcher"
            android:fromDegrees="0.0"
            android:pivotX="50.0%"
            android:pivotY="50.0%"
            android:toDegrees="1080" />
        <!-- 其中,toDegrees的值越大,转的圈圈越快 -->
    </item>
</layer-list>

不确定样式进度-2

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="1080" >
    <shape
        android:innerRadiusRatio="3"
        android:shape="ring"
        android:thicknessRatio="15"
        android:useLevel="false" >
        <gradient
            android:centerColor="#f00"
            android:centerY="0.50"
            android:endColor="#0f0"
            android:startColor="#00f"
            android:type="sweep"
            android:useLevel="false" />
    </shape>
</rotate>

确定样式进度

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:id="@android:id/background">
        <shape>
            <solid android:color="#f00" />
        </shape>
    </item>
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <solid android:color="#00f" />
            </shape>
        </clip>
    </item>
</layer-list>

Activity

public class MainActivity extends Activity {
    ProgressBar pbpb1;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout);
        pb = (ProgressBar) findViewById(R.id.pb);
        pb1 = (ProgressBar) findViewById(R.id.pb1);
        
        pb1.setMax(pb.getMax());
        pb1.setProgress(pb.getProgress());
        pb1.setProgressTintList(pb.getProgressTintList());//进度条颜色
        pb1.incrementProgressBy(-5);//进度值增加
        
        pb1.setSecondaryProgress(pb.getSecondaryProgress());
        pb1.setSecondaryProgressTintList(pb.getSecondaryProgressTintList());
        pb1.incrementSecondaryProgressBy(5);//第二个进度条进度值增加
    }
}

附件列表

     

    ProgressBar 系统进度条【案例】

    标签:风格   order   encoding   over   idt   技术   public   不显示   color   

    原文地址:http://www.cnblogs.com/baiqiantao/p/4dfbaca02ccf222feab5eee2ecc25cf8.html

    (0)
    (0)
       
    举报
    评论 一句话评论(0
    登录后才能评论!
    © 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
    迷上了代码!