• android之进度条


    xml引用

    <ProgressBar
            android:id="@+id/pb_progressbar"
            style="@style/StyleProgressBarMini"
            android:layout_width="fill_parent"
            android:layout_height="40dip"
            android:layout_margin="30dp"
            android:background="@drawable/shape_progressbar_bg"
            android:max="100"
            android:progress="0" />
    ProgressBar

    样式styles.xml

    <resources>
    
        <!--
            Base application theme, dependent on API level. This theme is replaced
            by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
        -->
        <style name="AppBaseTheme" parent="android:Theme.Light">
            <!--
                Theme customizations available in newer API levels can go in
                res/values-vXX/styles.xml, while customizations related to
                backward-compatibility can go here.
            -->
        </style>
    
        <!-- Application theme. -->
        <style name="AppTheme" parent="AppBaseTheme">
            <!-- All customizations that are NOT specific to a particular API-level can go here. -->
        </style>
    
        <style name="StyleProgressBarMini" parent="@android:style/Widget.ProgressBar.Horizontal">
            <item name="android:maxHeight">50dip</item>
            <item name="android:minHeight">10dip</item>
            <item name="android:indeterminateOnly">false</item>
            <item name="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item>
            <item name="android:progressDrawable">@drawable/shape_progressbar_mini</item>
        </style>
    </resources>
    styles.xml

    边框

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
        <!--边框填充的颜色 --> 
        <solid android:color="#cecece" />
        <!-- 设置进度条的四个角为弧形 --> 
        <!-- android:radius 弧形的半径  -->
        <corners android:radius="90dp" />
        <!-- padding:边界的间隔 -->
        <padding
            android:bottom="1dp"
            android:left="1dp"
            android:right="1dp"
            android:top="1dp" />
    </shape>
    shape_progressbar_bg.xml

    填充

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
        <item android:id="@android:id/background">
            <shape>
                <corners android:radius="5dip" />
                    <gradient
                        android:angle="270"
                        android:centerY="0.75"
                        android:endColor="@color/white"
                        android:startColor="@color/white" />
            </shape>
        </item>
        <item android:id="@android:id/secondaryProgress">
            <clip>
                <shape>
                    <corners android:radius="0dip" />
                    <gradient
                    android:angle="270"
                    android:centerY="0.75"
                    android:endColor="#df0024"
                    android:startColor="#df0024" />
                </shape>
            </clip>
        </item>
        <item android:id="@android:id/progress">
            <clip>
                <shape>
                    <corners android:radius="5dip" />
                    <gradient
                        android:angle="270"
                        android:centerY="0.75"
                        android:endColor="@color/blue"
                        android:startColor="@color/blue" />
                </shape>
            </clip>
        </item>
    </layer-list>
    shape_progressbar_mini.xml

    后台设置

    import android.os.Bundle;
    import android.os.Handler;
    import android.app.Activity;
    import android.util.Log;
    import android.view.Menu;
    import android.widget.ProgressBar;
    
    public class MainActivity extends Activity {
        private ProgressBar pb_progressbar;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            pb_progressbar=(ProgressBar)findViewById(R.id.pb_progressbar);
            handler.postDelayed(runnable, DELYED); //启动定时器
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
        //定時器
        private int DELYED= 500;
        private int timeOut=0;
        Handler handler = new Handler();
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                try {
                    handler.postDelayed(this, DELYED);
                    timeOut++;
                    pb_progressbar.setProgress(timeOut);
                    
                } catch (Exception e) {
                    Log.e("->runnable定时器", e.toString());
                }
            }
        };
    }
    Java代码
  • 相关阅读:
    【BZOJ4864】[BeiJing 2017 Wc]神秘物质 Splay
    【BZOJ3438】小M的作物 最小割
    【BZOJ3436】小K的农场 差分约束
    【BZOJ2879】[Noi2012]美食节 动态加边网络流
    【BZOJ1070】[SCOI2007]修车 费用流
    【BZOJ1486】[HNOI2009]最小圈 分数规划
    搜索ABAP程序代码中的字符串
    自定义表的维护
    用户名转换成中文名
    日期计算
  • 原文地址:https://www.cnblogs.com/huangzhen22/p/5025904.html
Copyright © 2020-2023  润新知