我在我的应用程序中使用ProgressBar,我在onProgressUpdate中更新AsyncTask.到现在为止还挺好.
我想要做的是为进度更新设置动画,这样它不仅可以"跳转"到值,而且可以平滑地移动到它.
我尝试这样做运行以下代码:
this.runOnUiThread(new Runnable() {
@Override
public void run() {
while (progressBar.getProgress() < progress) {
progressBar.incrementProgressBy(1);
progressBar.invalidate();
try {
Thread.sleep(10);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
问题是进度条在完成其最终值(进度变量)之前不会更新其状态.中间的所有状态都不会显示在屏幕上.调用progressBar.invalidate()也没有帮助.
有任何想法吗?谢谢!
在我的项目中我想使用ProgressBar并且我想设置平滑倒计时动画。
我下面写的代码顺利动画,当一套1000毫秒(1秒)的时间演出顺利 animation,但我想要一套10000ms(10秒)的时间。
当持续时间设置为 10000 毫秒(10 秒)时,动画不流畅并显示片段倒计时。
但我想一套10000ms的时间,并显示顺利倒计时。
public class SimpleFrag extends Fragment {
TextView toolbar_title;
RelativeLayout toolbar;
private ProgressBar progressBar;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_simple, container, false);
ButterKnife.bind(this, view);
toolbar_title = getActivity().findViewById(R.id.toolbar_title);
toolbar = getActivity().findViewById(R.id.toolbar);
progressBar = view.findViewById(R.id.progress);
return view;
} …Run Code Online (Sandbox Code Playgroud)