带内边距的 Android 进度条
我想让我的进度条看起来像这样:
我不想使用图像,所以我有尝试用形状来做这个:
<item android:id="@android:id/background">
<shape>
<corners android:radius="50dp" />
<gradient
android:angle="270"
android:centerColor="#2a2723"
android:centerY="0.75"
android:endColor="#2a2723"
android:startColor="#2a2723" />
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="50dp" />
<gradient
android:angle="270"
android:centerColor="#16e61c"
android:centerY="0.75"
android:endColor="#9dfd6e"
android:startColor="#16e61c" />
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="50dp" />
<gradient
android:angle="270"
android:endColor="#9dfd6e"
android:startColor="#16e61c" />
</shape>
</clip>
</item>
但我无法为绿线设置填充(我尝试在任何可能的地方设置它),而且我也无法制作这样的圆角(看起来 corners android:radius
不起作用)。请帮我
I want to make my progress bar looks something like that:
I dont want to use images, so I have tried to make this with the shapes:
<item android:id="@android:id/background">
<shape>
<corners android:radius="50dp" />
<gradient
android:angle="270"
android:centerColor="#2a2723"
android:centerY="0.75"
android:endColor="#2a2723"
android:startColor="#2a2723" />
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="50dp" />
<gradient
android:angle="270"
android:centerColor="#16e61c"
android:centerY="0.75"
android:endColor="#9dfd6e"
android:startColor="#16e61c" />
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="50dp" />
<gradient
android:angle="270"
android:endColor="#9dfd6e"
android:startColor="#16e61c" />
</shape>
</clip>
</item>
But I cant set padding for the green line (Ive tried to set its everywhere where it was possible), and also I can't make such round corners (looks like corners android:radius
isn't working). Please help me
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
查看我的博客
see my blog
一个简单的解决方法是将进度条包装到具有圆形形状且背景颜色与进度条相同的布局中。
示例进度条可绘制 (drawable/progress_bar.xml):
进度条样式:
布局形状 (drawable/rounded_shape.xml):
活动布局:
效果:
要增加进度条的填充,您必须增加 rounded_shape 文件中的填充。
A simple workaround is to wrap progress bar into layout which has rounded shape and same background color as progress bar.
Sample progress bar drawable (drawable/progress_bar.xml):
Progress bar style:
Layout shape (drawable/rounded_shape.xml):
Activity layout:
Effect:
To increase padding of progress bar you have to increase padding in rounded_shape file.
是的,不使用@Nykakin 建议的图像就可以做到这一点。要为进度添加内边距和圆角,就是对项目进度使用列表层。
Yes it's possible to have exactly that without using image like @Nykakin has suggested. To have the padding and the rounded corner for the progress is to use list-layer for the item progress.
不幸的是我没有找到解决我的问题的方法。我可以制作圆角的唯一方法是使用圆角 9 间距图像
有一个很好的教程可以做到这一点:http://blog.mediarain.com/2011/04/android-custom-progressbar-with-rounded-corners/
Unfortunately I didn't find solution for my problem. The only way I could make round corners was to use rounded 9-pitch image
There is a good tutorial to do that: http://blog.mediarain.com/2011/04/android-custom-progressbar-with-rounded-corners/