Reputation: 9049
LinearLayout spinnerLayout = new LinearLayout(this);
addContentView(spinnerLayout,new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
ProgressBar spinner = new ProgressBar(this);
spinnerLayout.addView(spinner);
Of course, the spinner is in the top left corner. I've searched and found the xml method, but I want a java solution.
Upvotes: 1
Views: 3680
Reputation: 24857
LinearLayout spinnerLayout = new LinearLayout(this);
spinnerLayout.setGravity(Gravity.CENTER);
addContentView(spinnerLayout,new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
ProgressBar spinner = new ProgressBar(this);
spinnerLayout.addView(spinner);
That should work
Upvotes: 4