ANDROID_MARS学习笔记_S01_011ProgressBar

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ANDROID_MARS学习笔记_S01_011ProgressBar相关的知识,希望对你有一定的参考价值。

1.xml

<RelativeLayout 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: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=".MainActivity" >

    <ProgressBar
        android:id="@+id/firstProgressBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="?android:attr/progressBarStyleHorizontal" />
    
    <Button 
        android:id="@+id/firstButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/firstProgressBar"
        android:text="增加第一进度"/>
    
    <Button 
        android:id="@+id/secondButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/firstButton"
        android:text="增加第二进度"/>

</RelativeLayout>

 

2.java

 1 package com.marschen.s01_e17_progressbar;
 2 
 3 import android.app.Activity;
 4 import android.os.Bundle;
 5 import android.view.Menu;
 6 import android.view.View;
 7 import android.view.View.OnClickListener;
 8 import android.widget.Button;
 9 import android.widget.ProgressBar;
10 
11 public class MainActivity extends Activity {
12 
13     private ProgressBar progressBar;
14     private Button firstButton;
15     private Button secondButton;
16     @Override
17     protected void onCreate(Bundle savedInstanceState) {
18         super.onCreate(savedInstanceState);
19         setContentView(R.layout.activity_main);
20         
21         progressBar = (ProgressBar)findViewById(R.id.firstProgressBar);
22         firstButton = (Button)findViewById(R.id.firstButton);
23         secondButton = (Button)findViewById(R.id.secondButton);
24         
25         progressBar.setMax(100);
26         
27         firstButton.setOnClickListener(new FirstListener());
28         secondButton.setOnClickListener(new SecondListener());
29         
30     }
31     
32     class FirstListener implements OnClickListener{
33 
34         @Override
35         public void onClick(View v) {
36             progressBar.incrementProgressBy(10);
37         }
38         
39     }
40     
41     class SecondListener implements OnClickListener{
42 
43         @Override
44         public void onClick(View v) {
45             progressBar.incrementSecondaryProgressBy(20);
46         }
47         
48     }
49 
50     @Override
51     public boolean onCreateOptionsMenu(Menu menu) {
52         // Inflate the menu; this adds items to the action bar if it is present.
53         getMenuInflater().inflate(R.menu.main, menu);
54         return true;
55     }
56 
57 }

 

以上是关于ANDROID_MARS学习笔记_S01_011ProgressBar的主要内容,如果未能解决你的问题,请参考以下文章

ANDROID_MARS学习笔记_S01_006ImageView

ANDROID_MARS学习笔记_S01_012_RatingBar

ANDROID_MARS学习笔记_S01_005CheckBox

ANDROID_MARS学习笔记_S01原始版_010_ContentProvider

ANDROID_MARS学习笔记_S01原始版_009_SQLite

ANDROID_MARS学习笔记_S01原始版_005_RadioGroupCheckBoxToast