Android常见控件— — —ProgressBar
2024-08-25 11:09:59
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);
}
}
}); } }
最新文章
- iOS NSNotificationCenter详解
- Intellij IDEA工具Java web 环境搭建
- EasyUI中datagrid控件的使用 设置多行表头(两行或多行)
- (译)利用ASP.NET加密和解密Web.config中连接字符串
- 隐知识:reloadData 方法之后,view并不会立即更新其contentSize
- iOS学习笔记---简单的学习总结
- ios学习笔记第三天之UI控件
- Git分支-分支简介
- Java 前端模板引擎学习:thymeleaf 模板引擎
- 记录一次.Net框架Bug发现和提交过程:.Net Framework和.Net Core均受影响
- Django + Mysql 中关于时间异常返回500错误的解决
- <;构建之法>;10,11,12章的读后感
- 第一阶段——站立会议总结DAY01
- MongoDB给数据库创建用户
- 前端弹窗展示后台html文件
- webkit开源项目
- 第十周课下作业-IPC
- Working C# code for MySql5.5 Stored Procedures IN parameters
- 源码分析:动态分析 Linux 内核函数调用关系
- Hibernate 一对一映射(惟一外键)