ANDROID_MARS学习笔记_S01_011ProgressBar
生活随笔
收集整理的這篇文章主要介紹了
ANDROID_MARS学习笔记_S01_011ProgressBar
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文檔是這樣來設置樣式
?
<ProgressBarandroid:layout_width="wrap_content"android:layout_height="wrap_content"style="@android:style/Widget.ProgressBar.Small"android:layout_marginRight="5dp" />
?
?
?
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" ><ProgressBarandroid: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 }
?
轉載于:https://www.cnblogs.com/shamgod/p/5186986.html
總結
以上是生活随笔為你收集整理的ANDROID_MARS学习笔记_S01_011ProgressBar的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python字符串的修改以及传参
- 下一篇: 深圳的技工学校哪个比较好,希望是公立的!