Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - programmatically creating view progressBar

How to create horizontal progessBar without XML or how to declare XML properties without XML contentView?

I have layout in .java file and I want to set progressBar to horizontal and set its width/location.

RelativeLayout fv = new RelativeLayout(this);
panel = new Panel(this);
fv.addView(panel);
ProgressBar pb = new ProgressBar(this);
//pb.? - progress bar parameters
fv.addView(pb);
setContentView(fv);

Oh, and it can't be a pop-up window. I need progressBar on top of touch-enabled canvas layer..

like image 395
yosh Avatar asked Jan 24 '11 16:01

yosh


1 Answers

In the constructor, do this:

ProgressBar pb = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);

You can replace the null with an AttributeSet, typically you would need one of Android's AttributSets anyway. You can then set its width/location using the standard View methods.

like image 152
Jems Avatar answered Oct 24 '22 03:10

Jems