控件置顶[置顶] Android常用UI控件之ProgressBar
PS:明天上午,非常郁闷,有很多简单基础的问题搞得我有些迷茫,哎,代码几天不写就忘。目前又不当COO,还是得用心记代码哦!
明天我们学习如何实现各种样式的ProgressBar,上面给出该场景的案例:
一、案例代码
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.progressbar" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".ProgressBarMainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
strings.xml
<resources> <string name="app_name">ProgressBar大世界</string> </resources>
main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="小圆形进度条" /> <ProgressBar style="?android:attr/progressBarStyleSmallTitle" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="中圆形进度条" /> <ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="大圆形进度条" /> <ProgressBar style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="水平进度条" /> <ProgressBar style="?android:attr/progressBarStyleHorizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:max="100" android:progress="30" /> <ProgressBar android:id="@+id/progressBar" style="?android:attr/progressBarStyleHorizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:max="100" android:progress="30" android:secondaryProgress="60" /> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="增加刻度" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="减小刻度" /> </LinearLayout> </LinearLayout>
ProgressBarMainActivity.java
package com.android.progressbar; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; import android.widget.Button; import android.widget.ProgressBar; /** * ProgressBar案例:各种样式的进度条 * 向用户展示当前任务的进度 * @author lynnli1229 */ public class ProgressBarMainActivity extends Activity implements OnClickListener{ private ProgressBar progressBar; private Button button1, button2; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 设置有刻度效果的窗口 requestWindowFeature(Window.FEATURE_PROGRESS); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.main); progressBar = (ProgressBar) findViewById(R.id.progressBar); setProgressBarVisibility(true); setProgressBarIndeterminate(true); setProgress(3500); button1 = (Button) findViewById(R.id.button1); button2 = (Button) findViewById(R.id.button2); button1.setOnClickListener(this); button2.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.button1: progressBar.setProgress((int) (progressBar.getProgress() * 1.2)); progressBar.setSecondaryProgress((int) (progressBar.getSecondaryProgress() * 1.2)); break; case R.id.button2: progressBar.setProgress((int) (progressBar.getProgress() * 0.8)); progressBar.setSecondaryProgress((int) (progressBar.getSecondaryProgress() * 0.8)); break; } } }
二、案例效果
文章结束给大家分享下程序员的一些笑话语录:
这年头的互联网真是娱乐了中国,网民们从各种各样的“门”里钻来钻去,又有好多“哥”好多“帝”,值得大家品味不已……网络经典语录,关于IT与互联网,经典与您分享!
---------------------------------
原创文章 By
控件和置顶
---------------------------------