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解决方案。
答案 0 :(得分: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);
那应该有用