用户界面 View(六)
<ProgressBar android:id=”@+id/ProgressBar01″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”>
</ProgressBar>
package android.basic.lesson11;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
public class MainHelloProgressBar extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//在标题条里放置进度条。请求窗口特色风格,这里设置成不明确的进度风格
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.main);
//设置标题栏中的不明确的进度条是否可以显示,当你需要表示处理中的时候设置为True,处理完毕后设置为false
setProgressBarIndeterminateVisibility(true);
}
}
<?xml version=”1.0″ encoding=”utf-8″?><LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”android:orientation=”vertical”android:background=”#003399″android:layout_width=”fill_parent”android:layout_height=”fill_parent”><ProgressBar android:id=”@+id/ProgressBar01″android:layout_width=”wrap_content”android:layout_height=”wrap_content”></ProgressBar><ProgressBar android:id=”@+id/ProgressBar02″style=”?android:attr/progressBarStyleLarge” 大圆圈android:layout_width=”wrap_content”android:layout_height=”wrap_content”></ProgressBar><ProgressBar android:id=”@+id/ProgressBar03″style=”?android:attr/progressBarStyleSmall” 小圆圈android:layout_width=”wrap_content”android:layout_height=”wrap_content”></ProgressBar><ProgressBar android:id=”@+id/ProgressBar03″style=”?android:attr/progressBarStyleSmallTitle” 标题条的样式android:layout_width=”wrap_content”android:layout_height=”wrap_content”></ProgressBar>
</LinearLayout>
<ProgressBar android:id=”@+id/ProgressBar04″style=”?android:attr/progressBarStyleHorizontal”android:layout_marginLeft=”10dp”
android:layout_marginRight=”10dp”android:max=”100″ 最大刻度按100算android:progress=”30″ 第一进度是30android:secondaryProgress=”80″ 第二进度是80android:layout_width=”fill_parent” 进度条的显示长度是铺满父窗口android:layout_height=”wrap_content”></ProgressBar><?xml version=”1.0″ encoding=”utf-8″?><LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”android:orientation=”vertical”android:background=”#003399″android:layout_width=”fill_parent”android:layout_height=”fill_parent”><ProgressBar android:id=”@+id/ProgressBar04″style=”?android:attr/progressBarStyleHorizontal”android:layout_marginTop=”10dp”android:layout_marginLeft=”10dp”android:layout_marginRight=”10dp”android:max=”100″android:progress=”30″android:secondaryProgress=”80″android:layout_width=”fill_parent”android:layout_height=”wrap_content”></ProgressBar>
</LinearLayout>
package android.basic.lesson11;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
public class MainHelloProgressBar extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//设置窗口进度条特性风格
requestWindowFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.main);
//设置进度条可见性
setProgressBarVisibility(true);
//设置进度条进度值,要乘以100的
setProgress(60*100);
setSecondaryProgress(80*100);
}
}
pb.incrementProgressBy(5); //ProgressBar进度值增加5
十二、SeekBar 拖动条 滑动条
package android.basic.lesson11;
import android.app.Activity;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.widget.Toast;
public class MainHelloSeekBar extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//找到拖动条和文本框
final SeekBar sb = (SeekBar) findViewById(R.id.SeekBar01);
final TextView tv1 = (TextView) findViewById(R.id.TextView01);
//设置拖动条的初始值和文本框的初始值
sb.setMax(100);
sb.setProgress(30);
tv1.setText("当前进度:" + sb.getProgress());
//设置拖动条改变监听器
OnSeekBarChangeListener osbcl = new OnSeekBarChangeListener() {
@Override
&n