android - 开发中进度条的选择
ringa_lee
ringa_lee 2017-04-18 09:16:17
0
4
527

使用Progress控件很方便,但是如果有居中需求的话,某些场景会增加一层布局嵌套
而且每个布局都要书写,很麻烦

而使用ProgressDialog 书写起来很方便,但是某些场景不能很直接的提供正确的上下文.(容器不是activityfragment 时)

各位大哥在实际开发中如何实现进度条的需求的?

//我尝试这样操作的情况,下 在app第一次进入的时候,我点击按钮向容器上添加progressbar的时候,这个progressbar是不会旋转的,卡在界面上
//而关闭这个activity后(app中还有activity存在),再次进入activity 继续添加,这时候progressbar就会旋转了,这是为什么呢?
ProgressBar progressBar = new ProgressBar(this);
ViewGroup decorView = (ViewGroup) getWindow().getDecorView();
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER);
progressBar.setLayoutParams(layoutParams);
decorView.addView(progressBar);
ringa_lee
ringa_lee

ringa_lee

reply all(4)
Peter_Zhu

I can’t give you any constructive advice on this. Sometimes to save trouble, I will write an XML interface for ProgressBar, inflate it when using it and insert it directly into the rootView. If you like, I can re-implement this logic in BaseActivity. One layer of encapsulation can basically meet some simple needs.
To make it more complicated, let the progressBar interact with the user's operations. For example, if an editing interface has an entrance for uploading pictures, we can change the submit key to the Progress Widget while the user is waiting for the upload after selecting the picture. Blocking user operations can also effectively prompt progress.
As for ProgressDialog, I think it is too blocking. Except in some scenarios with strong logical order, such as when certain files must be loaded before proceeding to the next step, this is generally not recommended.

Ty80

As long as you can get itContext, 那就接着用ProgressDialog

Take Application as an example:

  1. Write an Activity as a proxy for Dialog popup

  2. startActivity(Intent)

Peter_Zhu

I’m actually more interested in the question of what kind of scenario the “context is not provided correctly” in the question is. What situations did the questioner encounter that he couldn't get? progressbar可以拿到上下文而progressdialog

巴扎黑

If it is not a container of activity or fragment, then this container must be in activity or fragment when it is created.
If it is not, then its parent container or parent container must be in activity or fragment.
In this case, then you can pass the context level by level through the constructor, right?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template