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

问题描述

我想做加入code一个进度条,并使其确定的:

I'm trying to do add a progressbar in code and make it determinate:

progressBar = new ProgressBar(getActivity());
progressBar.setLayoutParams(layoutParams);
parent.addView(progressBar, index);
progressBar.setId(id.list_item_secondary);
progressBar.setProgressDrawable(getResources().getDrawable(drawable.progress_horizontal));
progressBar.setIndeterminate(false);
progressBar.setMax(100);

progressBar.setIndeterminate(假) isIndeterminate 仍是真实的进度保持显示不确定的圆。

After progressBar.setIndeterminate(false), isIndeterminate is still true and the progress keeps shows the indeterminate circle.

我怎样才能使它确定的?

推荐答案

从进度源$ C ​​$ C 此处,要调用构造函数是23​​7行是调用构造函数中的行241进而调用构造函数线245风格:

From the ProgressBar source code here, the constructor you are calling is in line 237 which is calling the constructor in line 241 which in turn calls the constructor in line 245 with the style:

com.android.internal.R.attr.progressBarStyle

此样式属性的android:indeterminateOnly设置为true,在默认情况下让你的来电setIndeterminate被忽略。见在行433的功能说明。

This style has the attribute android:indeterminateOnly set to true by default so your calls to setIndeterminate are ignored. See the function description at line 433.

我还没有做到这一点,但我认为如果你调用线245的构造是这样的:

I haven't done this but I assume that if you call the constructor in line 245 like this:

progressBar = new ProgressBar(getActivity(), null, <Your Style ID>);

通过作为第三个参数与Android风格的定义:indeterminateOnly假它应该工作。根据源$ C ​​$ C我认为setIndeterminate有只启用它,而不是禁用它。

passing as the third parameter a style definition with android:indeterminateOnly to false it should work. Based in the source code I assume that setIndeterminate is there only to enable it and not to disable it.

希望这有助于...

这篇关于如何让Android进度定在code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 15:43