xml布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<LinearLayout
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:text="图片进度条" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="颜色进度" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="动画进度条" />
</LinearLayout>
<ProgressBar
android:id="@+id/progressbar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="false"
android:indeterminateDrawable="@anim/loading"
android:layout_centerInParent="true"
android:visibility="gone" />
<ProgressBar
android:id="@+id/progressbar2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="false"
android:indeterminateDrawable="@drawable/indetermined_progress"
android:layout_centerInParent="true"
android:visibility="gone" />
<ProgressBar
android:id="@+id/progressbar3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="false"
android:indeterminateDrawable="@anim/waitting"
android:layout_centerInParent="true"
android:visibility="gone" />
</RelativeLayout>
Java代码
public class MainActivity extends Activity implements OnClickListener {
private Button btn_progress1;
private Button btn_progress2;
private Button btn_progress3;
private ProgressBar progress1;
private ProgressBar progress2;
private ProgressBar progress3;
private boolean isShow1 = false;
private boolean isShow2 = false;
private boolean isShow3 = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_progress1 = (Button) findViewById(R.id.button1);
btn_progress2 = (Button) findViewById(R.id.button2);
btn_progress3 = (Button) findViewById(R.id.button3);
btn_progress1.setOnClickListener(this);
btn_progress2.setOnClickListener(this);
btn_progress3.setOnClickListener(this);
progress1 = (ProgressBar) findViewById(R.id.progressbar1);
progress2 = (ProgressBar) findViewById(R.id.progressbar2);
progress3 = (ProgressBar) findViewById(R.id.progressbar3);
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.button1:
if(!isShow1){
progress1.setVisibility(View.VISIBLE);
isShow1 = true;
}else{
progress1.setVisibility(View.GONE);
isShow1 = false;
}
break;
case R.id.button2:
if(!isShow2){
progress2.setVisibility(View.VISIBLE);
isShow2 = true;
}else{
progress2.setVisibility(View.GONE);
isShow2 = false;
}
break;
case R.id.button3:
if(!isShow3){
progress3.setVisibility(View.VISIBLE);
isShow3 = true;
}else{
progress3.setVisibility(View.GONE);
isShow3 = false;
}
break;
}
}
}