android中进度条—基础篇

简介:


本文转自 llb988 51CTO博客,原文链接:http://blog.51cto.com/llb988/486075,如需转载请自行联系原作者

android  progrssbar 

  

  

进度条即计算机在处理文件时,实时的,以图片形式显示处理文件的速度,完成度,剩余未完成文件的大小,和可能需要处理时间,一般以水平或者是图形条状显示

 

类代码

package com.smart;

import android.app.Activity;
import android.content.DialogInterface;
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;

public class Main extends Activity implements OnClickListener {

 // 各位在导入包的时候,记住要导入import android.view.View.OnClickListener;
 private ProgressBar progressbarHorizontal;

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
  setContentView(R.layout.main);

  setProgressBarIndeterminateVisibility(true);
  progressbarHorizontal = (ProgressBar) findViewById(R.id.progressBarHorizontal);
  Button button1 = (Button) findViewById(R.id.button1);
  Button button2 = (Button) findViewById(R.id.button2);
  // 绑定器
  button1.setOnClickListener(this);
  button2.setOnClickListener(this);

 }

 @Override
 public void onClick(View view) {

  switch (view.getId()) {
  // 处理“增加进度"按钮事件
  case R.id.button1:
   progressbarHorizontal.setProgress((int) (progressbarHorizontal
     .getProgress() * 1.18));
   progressbarHorizontal
   .setSecondaryProgress((int) (progressbarHorizontal
     .getSecondaryProgress() * 1.18));
   break;
  // 处理“减少进度"按钮事件
  case R.id.button2:
   progressbarHorizontal.setProgress((int) (progressbarHorizontal
     .getProgress() * 0.88));
   progressbarHorizontal
     .setSecondaryProgress((int) (progressbarHorizontal
       .getSecondaryProgress() * 0.88));
   break;
  }

 }

}

main.xml

代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="SMART圆形进度条1"
    />
    <ProgressBar
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     style="?android:attr/progressBarStyleSmallTitle"/>
    <TextView  
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="SMART圆形进度条2"
    />
      <ProgressBar
     android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    />
    <TextView  
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="SMART圆形进度条3"
    />
      <ProgressBar
     android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    style="?android:attr/progressBarStyleLarge"
    />
    <TextView  
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="SMART水平进度条4"
    />
      <ProgressBar
     android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    style="?android:attr/progressBarStyleHorizontal"
     android:max="100"
    android:progress="30"
    />
       <ProgressBar
       android:id="@+id/progressBarHorizontal"
     android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    style="?android:attr/progressBarStyleHorizontal"
    android:max="100"
    android:progress="30"
 android:secondaryProgress="60"
 android:layout_marginTop="20dp"
    
    />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    
    <Button
    android:id="@+id/button1"
     android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:text="进度增加"
    />
    
        <Button
    android:id="@+id/button2"
     android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:text="进度减小"
    />

    </LinearLayout>
</LinearLayout>
 

相关文章
|
1月前
|
XML Java Android开发
Android实现自定义进度条(源码+解析)
Android实现自定义进度条(源码+解析)
68 1
|
10月前
|
Android开发 UED
Android 实现通知栏和进度条效果(适用于Android8.0以上)
Android 实现通知栏和进度条效果(适用于Android8.0以上)
122 0
|
26天前
|
Java API Android开发
19. 【Android教程】进度条 ProgressBar
19. 【Android教程】进度条 ProgressBar
20 4
|
1月前
|
XML API Android开发
Android 自定义View 之 圆环进度条
Android 自定义View 之 圆环进度条
|
1月前
|
XML Java Android开发
Android控件之基础控件——进度条类的view——TextView、Checkbox复选控件、RadioButton单选控件、ToggleButton开关、SeekBar拖动条、menu、弹窗
Android控件之基础控件——进度条类的view——TextView、Checkbox复选控件、RadioButton单选控件、ToggleButton开关、SeekBar拖动条、menu、弹窗
100 1
|
10月前
|
Android开发
Android 中ProgressDialog进度条对话框的使用(使用子线程模拟更新进度)
Android 中ProgressDialog进度条对话框的使用(使用子线程模拟更新进度)
126 0
|
1月前
|
XML API Android开发
Android 自定义View 之 饼状进度条
Android 自定义View 之 饼状进度条
|
1月前
|
Android开发 UED
[Android]ProgressBar进度条
[Android]ProgressBar进度条
45 0
|
1月前
|
XML Java Android开发
Android Studio App开发中异步任务AsynTask与异步服务IntentService的讲解与实战(实现四大名著的加载进度条 附源码)
Android Studio App开发中异步任务AsynTask与异步服务IntentService的讲解与实战(实现四大名著的加载进度条 附源码)
102 0
|
7月前
|
Android开发
android进度条
android进度条
41 0