首先是Progress的布局
相关参数有
1:style="?android:attr/progressBarStyleHorizontal"--------设置进度条显示的样式(水平方向的)
2:android:visibility="gone"---------设置为不可见
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
android:id="@+id/firstBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:visibility="gone"
/>
android:id="@+id/secondBar"
style="?android:attr/progressBarStyle"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:visibility="gone"
/>
android:id="@+id/myButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/progressBar_Button_Name"
/>
然后通过Activity调用布局文件
android进度条的默认大小为100;可以通过setProgress(int i);设置进度大小
并且android进度条默认是不可见的可以通过Progress.setVisibility(View.VISIBLE);设置可见
也可以设置为不可见:Progress.setVisibility(View.GONE);
package zhou.demo;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
public class ProgressBarTest extends Activity {
//对控件进行声明
private ProgressBar firstBar = null;
private ProgressBar secondBar = null;
private Button myButton = null;
private int i = 0;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//根据控件的ID来取得控件对象
firstBar = (ProgressBar)this.findViewById(R.id.firstBar);
secondBar = (ProgressBar)findViewById(R.id.secondBar);
myButton = (Button)findViewById(R.id.myButton);
myButton.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
if(i == 0){
//设置进度条可见
firstBar.setVisibility(View.VISIBLE);
secondBar.setVisibility(View.VISIBLE);
}else if(i < 100){
firstBar.setProgress(i);
firstBar.setSecondaryProgress(i+5);
secondBar.setProgress(i);
}else{
//设置进度条不可见
firstBar.setVisibility(View.GONE);
secondBar.setVisibility(View.GONE);
}
i += 10;
}
});
}
}
大小: 12.2 KB
分享到:
2011-06-10 00:29
浏览 4244
评论