我如何编程设置一个Android进度的大小?进度、大小、Android

2023-09-13 23:58:46 作者:青衫栀拾

我有一个扩展的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(进度);
 

解决方案 android studio怎么设置字体大小

您可以使用的LayoutParams改变的宽度和高度,以任何你想要的。

 进度进度=新进度(teste.this,空,android.R.attr.progressBarStyleHorizo​​ntal);

            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.