简体   繁体   中英

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.

    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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM