Android常见控件— — —ProgressBar
2016-02-29 17:18
549 查看
ProgressBar用于在界面上显示一个进度条,表示我们的程序正在加载一些数据。
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ProgressBar android:id="@+id/progress_bar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center"/> <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="progress消失"/> <Button android:id="@+id/button2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="progress重现"/> </LinearLayout>
package com.example.uiwidgettest2; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.*; public class edittextActivity extends Activity{ private ProgressBar progressBar = null; private Button btn1 = null; private Button btn2 = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.edittext); progressBar = (ProgressBar)findViewById(R.id.progress_bar); btn1 = (Button)findViewById(R.id.button1); btn2 = (Button)findViewById(R.id.button2); btn1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(progressBar.getVisibility() == View.VISIBLE){ progressBar.setVisibility(View.GONE); } } }); btn2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(progressBar.getVisibility() == View.GONE){ progressBar.setVisibility(v.VISIBLE); } } }); } }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ProgressBar android:id="@+id/progress_bar" android:layout_width="match_parent" android:layout_height="wrap_content" style="?android:attr/progressBarStyleHorizontal" android:max="100" /> <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="progress"/> </LinearLayout>
package com.example.uiwidgettest2; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.*; public class edittextActivity extends Activity{ private ProgressBar progressBar = null; private Button btn1 = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.edittext); progressBar = (ProgressBar)findViewById(R.id.progress_bar); btn1 = (Button)findViewById(R.id.button1); btn1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int progress = progressBar.getProgress(); progress = progress+10; if(progressBar.getProgress() <= 100){ progressBar.setProgress(progress); } } }); } }
相关文章推荐
- Android SDK Manager 设置代理
- Android 属性动画(Property Animation) 全然解析 (下)
- Android binder机制驱动层学习
- 基于Netty实现的Android 消息推送(即时通信)的解决方案
- android自定义多功能EditText 边框状态和删除内容
- Android 线程本地变量<一> ThreadLocal源码解析
- Android 深入理解Android中的自定义属性
- Android中的复制粘贴
- Android动态加载一
- Android 自定义View (二) 进阶
- android 存储目录
- Android抽象布局——include、merge 、ViewStub
- Android开发常用命令行
- Android studio(1.4.1) NDK开发
- Android应用中实现选择本地文件与目录的实例分享
- Android事件传递机制
- Android 上的代码阅读器 CoderBrowserHD 修改支持 go 语言代码
- android动态换肤系列3——从apk文件中获取Resources对象(上)
- Android Studio学习总结
- 关于androidannotations(注解)的理解和使用(文档篇)