Android 如何将 ProgressBar 的样式更改为小?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3500398/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 10:29:28  来源:igfitidea点击:

How can I change the style of a ProgressBar to small?

androidandroid-progressbarandroid-styles

提问by Janusz

I have some difficulties finding the correct way to specify that a progress bar should have the small indefinite style.

我很难找到正确的方法来指定进度条应该具有小的不确定样式。

I would be glad if somebody could provide an example for me and others that do a quick search for this information.

如果有人可以为我和其他快速搜索此信息的人提供示例,我会很高兴。

回答by Janusz

The solution is to change the style to

解决方案是将样式更改为

<ProgressBar
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   style="?android:attr/progressBarStyleSmall" />

回答by Rupesh Yadav

One more way to do it is

另一种方法是

style="@android:style/Widget.ProgressBar.Small" 

Ex_

前任_

<ProgressBar
 android:id="@+id/progress_bar"
 style="@android:style/Widget.ProgressBar.Small"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:padding="7dip"
 arandroid:visibility="visible" />

回答by Sileria

Here is how to do it programmatically:

以下是如何以编程方式执行此操作:

ProgressBar progress = new ProgressBar(ctx, null, android.R.attr.progressBarStyleSmall);

回答by Jaspreet Chhabra

This may be of use:

这可能有用:

style="?android:attr/android:progressBarStyleSmall"

回答by Sanjeev Pal

 <ProgressBar
        android:id="@+id/progressBar1"
        android:layout_width="wrap_content
        style="?android:attr/progressBarStyleSmallTitle"
        android:layout_height="wrap_content" />

回答by CoolMind

According to the answer of @Rupesh Yadav, you can see a structure of the style @android:style/Widget.ProgressBar.Small:

根据@Rupesh Yadav 的回答,您可以看到样式的结构@android:style/Widget.ProgressBar.Small

<style name="Widget.ProgressBar.Small">
    <item name="indeterminateDrawable">@drawable/progress_small_white</item>
    <item name="minWidth">16dip</item>
    <item name="maxWidth">16dip</item>
    <item name="minHeight">16dip</item>
    <item name="maxHeight">16dip</item>
</style>

I can confirm that setting min and max sizes solves the problem. Setting width and height explicitly doesn't change the size of the ProgressBar. So you can make your own style.

我可以确认设置最小和最大尺寸可以解决问题。显式设置宽度和高度不会更改 ProgressBar 的大小。所以你可以创造自己的风格。

回答by Suraj Vaishnav

You can change the size of progress bar easily scaleX and scaleY property, like this:

您可以轻松更改进度条的大小 scaleX 和 scaleY 属性,如下所示:

<ProgressBar
        android:id="@+id/progressBar"
        android:scaleX="0.5"
        android:scaleY="0.5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

Here,

这里,

scaleX:To change the width, so 0.5 will reduce the width to the half of the actual width

scaleX:改变宽度,所以0.5会减少宽度到实际宽度的一半

scaleY:To change the height, so 0.5 will reduce the height to the half of actual height

scaleY:改变高度,所以0.5会降低高度到实际高度的一半