我如何编程设置一个Android进度的大小? [英] How do I set an Android ProgressBar's Size programmatically?
本文介绍了我如何编程设置一个Android进度的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个扩展的ViewGroup
自定义视图。它包括一个进度
和的WebView
。我在显示进度
,而的WebView
加载。
这工作,但进度
太大。我如何使它更小?
下面是我的非工作code:
web视图=新的WebView(上下文);
webView.setWebViewClient(新MyWebChromeClient());
webView.loadUrl(文件://+路径);
addView(web视图);
进度=新进度(mContext,空,
android.R.attr.progressBarStyleSmall);
的LayoutParams PARAMS =新的LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
progressBar.setLayoutParams(PARAMS);
addView(进度);
解决方案
您可以使用的LayoutParams改变的宽度和高度,以任何你想要的。
进度进度=新进度(teste.this,空,android.R.attr.progressBarStyleHorizontal);
LinearLayout.LayoutParams PARAMS =新LinearLayout.LayoutParams(300,10);
progressBar.setLayoutParams(PARAMS);
LinearLayout中测试=新的LinearLayout(getApplicationContext());
test.addView(进度);
的setContentView(试验);
此外,当您添加视图,你可以使用这个code:
test.addView(进度,50,50);
,其中第一个参数是宽度,第二个是高度
I have a custom view that extends ViewGroup
. It includes a ProgressBar
and a WebView
. I'm displaying the ProgressBar
while the WebView
is loading.
This works, but the ProgressBar
is too big. How do I make it smaller?
Below is my non-working code:
webView = new WebView(context);
webView.setWebViewClient(new MyWebChromeClient());
webView.loadUrl("file://" + path);
addView(webView);
progressBar = new ProgressBar(mContext, null,
android.R.attr.progressBarStyleSmall);
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
progressBar.setLayoutParams(params);
addView(progressBar);
解决方案
You can use LayoutParams to change width and height to whatever you want.
ProgressBar progressBar = new ProgressBar(teste.this, null, android.R.attr.progressBarStyleHorizontal);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(300, 10);
progressBar.setLayoutParams(params );
LinearLayout test = new LinearLayout(getApplicationContext());
test.addView(progressBar);
setContentView(test);
Also when you add a view, you can use this code:
test.addView(progressBar,50,50);
where the first parameter is width and the second is height.
这篇关于我如何编程设置一个Android进度的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文