android 自定义圆形进度条

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;

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值