Adam
Adam

Reputation: 9049

Android setting progress bar in the center of the screen

    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

Answers (1)

Bobbake4
Bobbake4

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

Related Questions