2011-10-28 64 views
1
LinearLayout spinnerLayout = new LinearLayout(this); 
    addContentView(spinnerLayout,new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 

    ProgressBar spinner = new ProgressBar(this); 
    spinnerLayout.addView(spinner); 

當然,微調控制器位於左上角。我搜索並找到了xml方法,但我想要一個java解決方案。Android設置屏幕中心的進度條

回答

4
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); 

這應該工作