Jav*_*d98 5 android android-progressbar material-design
我正在开发一个使用不同进度条的应用程序,我希望它们看起来像Google合适的,带有圆角。
我为每个带有不同颜色的条都有一个自定义可绘制对象,并且它使外部拐角而不是内部拐角变圆,如您在此处看到的:
我的自定义可绘制对象是:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<corners android:radius="@dimen/progress_bar_rounded" />
<solid android:color="@color/progressbarBackground" />
</shape>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="@dimen/progress_bar_rounded" />
<solid android:color="@color/progressbarGreen" />
</shape>
</clip>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
进度条代码为:
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="@dimen/progress_bar_high"
android:id="@+id/GreenProgressBar"
android:indeterminate="false"
android:layout_marginLeft="15dp"
android:layout_gravity="center_vertical"
android:progressDrawable="@drawable/custom_green_progressbar" />
Run Code Online (Sandbox Code Playgroud)
我可以将某些库用作https://github.com/akexorcist/Android-RoundCornerProgressBar,但是由于这很简单,我认为这是不值得的。我也一直在寻找不同的线程,但是没有任何工作适合我。有什么想法,如果可能的话,不必使用.9.png图像?
非常感谢!
使用scale标签而不是clip:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<corners android:radius="@dimen/progress_bar_rounded" />
<solid android:color="@color/progressbarBackground" />
</shape>
</item>
<item android:id="@android:id/progress">
<scale android:scaleWidth="100%" android:useIntrinsicSizeAsMinimum="true">
<shape>
<corners android:radius="@dimen/progress_bar_rounded" />
<solid android:color="@color/progressbarGreen" />
<size android:width="@dimen/progress_bar_rounded"/>
</shape>
</scale>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)