控件——ProgressBar

来源:互联网 发布:java培训贷款骗局流程 编辑:程序博客网 时间:2024/06/05 15:48

这里写图片描述

这里写图片描述
左上是ProgressBar的 垂直风格 右上是ProgressBar的 水平风格
左下是SeekBar的对象 SeekBar是ProgressBar的子类
右下是RatingBar的对象 RatingBar是ProgressBar的子类

这里写图片描述

<ProgressBar       android:layout_width="wrap_content"       android:layout_height="wrap_content"       android:id="@+id/firstProgressBarId"       style="?android:attr/progressBarStyleSmall"/>    <ProgressBar        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:id="@+id/secondProgressBarId"        style="?android:attr/progressBarStyleInverse"        android:layout_below="@id/firstProgressBarId"/>    <ProgressBar        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:max="200"        android:progress="100"        android:secondaryProgress="150"        android:id="@+id/thirdProgressBarId"        android:layout_below="@id/secondProgressBarId"        style="?android:attr/progressBarStyleHorizontal"/>    <SeekBar        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:id="@+id/forthProgressBarId"        android:layout_below="@id/thirdProgressBarId"/>    <RatingBar        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:id="@+id/fifthProgressBarId"        android:layout_below="@id/forthProgressBarId"/>

style=”?android:attr/progressBarStyleHorizontal”
表示的是水平风格
默认为垂直风格

style=”?android:attr/progressBarStyleInverse”
表示的是反向风格
适用于activity底色为白色的界面

public class MainActivity extends AppCompatActivity {    private ProgressBar progressBar;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        progressBar = (ProgressBar)findViewById(R.id.firstProgressBarId);        //判断当前 progressBar 是否是 明确的        //所谓明确 也就是 水平风格是明确的 垂直风格不是明确的        boolean flag = progressBar.isIndeterminate();        //表示 在当前ProgressBar 主进度基础上 增加 10        progressBar.incrementProgressBy(10);        ////表示 在当前ProgressBar 第二进度基础上 增加 10        progressBar.incrementSecondaryProgressBy(10);    }    @Override    public boolean onCreateOptionsMenu(Menu menu) {        // Inflate the menu; this adds items to the action bar if it is present.        getMenuInflater().inflate(R.menu.menu_main, menu);        return true;    }    @Override    public boolean onOptionsItemSelected(MenuItem item) {        // Handle action bar item clicks here. The action bar will        // automatically handle clicks on the Home/Up button, so long        // as you specify a parent activity in AndroidManifest.xml.        int id = item.getItemId();        //noinspection SimplifiableIfStatement        if (id == R.id.action_settings) {            return true;        }        return super.onOptionsItemSelected(item);    }}
0 0