您的位置:首页 > 移动开发 > Android开发

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);
}
}
});

}

}


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: