ProgressBar

android:max   进度条长度最大值

android:progress  设定进度条当前进度值

android:secondaryProgress  第二进度条进度值

android:progressBarStyle    默认进度条样式

android:progressBarStyleHorizontal    水平样式

android:indeterminate 是否是不确定的进度条

 

incrementProgressBy(int diff) 指定增加的进度--即步长

1、对话框进度条

//MainActivity.java
public void showDialogProgress(View v){
        //创建对话框进度条
        ProgressDialog pd = new ProgressDialog(this);
        pd.setMax(100);
        //pd.setIndeterminate(false);
        pd.setProgress(30);
        pd.setCancelable(true);//是否可以被取消
        pd.setTitle("下载对话框");
        pd.setMessage("正在下载中...");
        pd.show();

//以下为简写        
//ProgressDialog pd2 = ProgressDialog.show(this,"downloading","downloading...",false,true);
    }
//relativelayout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/button1"
        android:layout_width="355dp"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="21dp"
        android:layout_marginTop="244dp"
        android:text="对话框进度条"
        android:onClick="showDialogProgress"/>
</RelativeLayout>

2、标题进度条(已废弃)

//设置进度条标题(该方法必须在setContextView之前)

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

//显示标题栏进度条

setProgressBarIndeterminateVisibility(true)

public class MainActivity_pb extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.progressbar);

        //设置 标题
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        setProgressBarIndeterminateVisibility(true);


    }
}

3、自定义进度条

通过图片自定义进度条

1)在res/drawable/下创建一个layer-list

2)设置ProgressBar的android:indeterminateDrawable属性

//progressbar.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ProgressBar
        android:id="@+id/progressBar5"
        style="?android:attr/progressBarStyle"
        android:layout_width="83dp"
        android:layout_height="86dp"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="31dp"
        android:layout_marginTop="329dp"
        android:indeterminateDrawable="@drawable/progress_bg"
        />


</RelativeLayout>
//progress_bg.xml,放在drawable下,设置旋转
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item>
        <rotate android:drawable="@drawable/jdt"
            android:fromDegrees="0"
            android:toDegrees="360"
            android:pivotX="50%"
            android:pivotY="50%" />
    </item>
</layer-list>

 

发布了47 篇原创文章 · 获赞 0 · 访问量 1万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览