本文介绍了有没有在显示Android中查看进度条的一般方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了如何显示,而在后台的数据加载进度条上无数的帖子。所有的建议,需要我们手动放置一个进度条的布局XML,然后使用的AsyncTask 来显示和隐藏的进度和有关的视图。

I have seen numerous posts on how to display progress bar while the data loads in the background. All suggestions requires we manually place a ProgressBar in the layout xml and then use an AsyncTask to show and hide the ProgressBar and the View in question.

不过,我想提出其在运行时编程创建进度泛型类,准确地把它放在一个有问题的看法,也许还略显阴凉处或在显示进度条模糊的看法。有这是一个Swing应用程序,我会画上。自从进度条这种情况下是相同的伪父母的孩子,因此我可以很容易地定位,作为中心。

However, I would like to make a generic class which creates the ProgressBar programmatically at runtime and place it exactly over the view in question and maybe also slightly shade or blur the view while the ProgressBar is displayed. Had this been a Swing application I would have painted my progress bar on the "glass pane" of the view after slightly shading it with gray. In that case since the progress bar is the child of the same pseudo parent hence I could easily position that as centred.

在Android的UI工具包,我不知道有任何这样的玻璃板的。我如何实现这样的效果?

In Android UI toolkit I am not aware of any such "glass panes". How do I achieve this effect?

推荐答案

好了,我不知道我得到的问题的权利,因为它似乎更容易对我来说比它可能是。但不管怎么说:

Well, I'm not sure I get the question right, because it seems easier to me than it might be. But anyway:

要编程实例化一个进度条,你需要做您的活动如下:

To instantiate programmatically a progress bar, you need to do the following in your activity:

    ProgressBar pb = new ProgressBar(this);
    ((ViewGroup) this.findViewById(R.id.view_that_will_contain_progressbar)).addView(pb);

这将增加视图到的ViewGroup view_that_will_contain_progressbar 。这ViewGroup中应该是的FrameLayout 如果你想在覆盖的其他信息。

This will add the view to the ViewGroup view_that_will_contain_progressbar. This ViewGroup should be a FrameLayout if you want to overlay over other information.

提示的:如果你想定制你的进度,你可以在布局文件中声明它,做实例化和(在活动/片段仍然)附加PB以下内容:

Tip: if you want to customize your ProgressBar, you can declare it in a layout file, and do the following to instantiate and attach the PB (still in your activity/fragment) :

this.getLayoutInflater()膨胀(R.layout.progressbar,父母);

与父母指的是家长要重视它。

with parent refering to the parent you want to attach it to.

这篇关于有没有在显示Android中查看进度条的一般方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 11:36