Java-在Android中创建不带xml的ProgressBar
作者:互联网
我正在尝试仅使用Java创建一个progressBar(而不是progressBar对话框).
我无法使其工作,我得到的是:
(不断旋转的图像)
这是我的代码:
b4 = new Button(this);
t4 = new ProgressBar(this);
b4.setId(4);
b4.setText(SensorData.sensorName[4]);
b4.setTypeface(null, 1);
b4.setTextSize(15);
b4.setGravity(Gravity.LEFT);
b4.setTextColor(R.color.black);
b4.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.icon, 0); // down
// t4.setId(4);
t4.setPadding(20, 10, 10, 10);
t4.setIndeterminate(false);
t4.setProgress(0);
t4.setScrollBarStyle(ProgressBar.SCROLLBARS_OUTSIDE_INSET);
t4.setMax(100);
t4.setVisibility(t4.VISIBLE);
sensorsView.addView(b4, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
sensorsView.addView(t4, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
b4.setOnClickListener(this);
我想要的是水平的progressBar,您知道我该怎么做吗?
谢谢.
解决方法:
更改此:
t4 = new ProgressBar(this);
对此:
t4 = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);
标签:android-progressbar,java,android 来源: https://codeday.me/bug/20191101/1983722.html