android – 瘦蓝色进度条

前端之家收集整理的这篇文章主要介绍了android – 瘦蓝色进度条前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试创建一个薄的蓝色进度条,类似于:

我对Drawables并不是那么好,但是我将ProgressBar更改为绿色,但我不确定如何使它变得薄而蓝:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. android:orientation="vertical"
  7. >
  8. <ProgressBar
  9. android:id="@+id/ProgressBar"
  10. android:layout_centerInParent="true"
  11. android:layout_width="fill_parent"
  12. android:layout_height="wrap_content"
  13. android:progressDrawable="@drawable/progress"
  14. style="@android:style/Widget.ProgressBar.Horizontal"
  15. android:visibility="gone"
  16. />
  17.  
  18. </LinearLayout>

可绘制

  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  4.  
  5. <item android:id="@android:id/background">
  6. <shape>
  7. <corners android:radius="5dip" />
  8. <gradient
  9. android:startColor="#ff9d9e9d"
  10. android:centerColor="#ff5a5d5a"
  11. android:centerY="0.75"
  12. android:endColor="#ff747674"
  13. android:angle="270"
  14. />
  15. </shape>
  16. </item>
  17.  
  18. <item android:id="@android:id/secondaryProgress">
  19. <clip>
  20. <shape>
  21. <corners android:radius="5dip" />
  22. <gradient
  23. android:startColor="#80ffd300"
  24. android:centerColor="#80ffb600"
  25. android:centerY="0.75"
  26. android:endColor="#a0ffcb00"
  27. android:angle="270"
  28. />
  29. </shape>
  30. </clip>
  31. </item>
  32. <item
  33. android:id="@android:id/progress"
  34. >
  35. <clip>
  36. <shape>
  37. <corners
  38. android:radius="5dip" />
  39. <gradient
  40. android:startColor="#33FF33"
  41. android:endColor="#008000"
  42. android:angle="270" />
  43. </shape>
  44. </clip>
  45. </item>
  46.  
  47. </layer-list>

解决方法

高度由android:layout_height =“wrap_content属性定义.例如,您可以将其设置为2dp,以创建更薄的进度条.

由于您使用渐变,因此更改颜色会更困难一些.所以你必须改变你的开始&结束颜色到某种蓝色.

我在用什么

  1. <ProgressBar
  2. android:id="@+id/progressbar"
  3. style="?android:attr/progressBarStyleHorizontal"
  4. android:layout_width="match_parent"
  5. android:layout_height="4dp"
  6. android:layout_marginTop="0.01dp"
  7. android:max="100"
  8. android:progress="50"
  9. android:progressDrawable="@drawable/myprogressbar"
  10. android:secondaryProgress="0" />

可绘制文件夹中的MyProgressBar.xml

  1. <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  2. <item android:id="@android:id/background">
  3. <shape>
  4. <corners android:radius="0dip" />
  5. <gradient android:startColor="#C0C0C0" android:centerColor="#F8F8FF"
  6. android:centerY="0.75" android:endColor="#ffffff" android:angle="90" />
  7. <stroke android:width="0.01dp" android:color="#6B8E23" />
  8. </shape>
  9. </item>
  10. <item android:id="@android:id/progress">
  11. <clip>
  12. <shape>
  13. <corners android:radius="0dip" />
  14. <gradient android:startColor="#9ACD32" android:endColor="#FFFF00"
  15. android:angle="90" />
  16. <stroke android:width="1dp" android:color="#6B8E23" />
  17. </shape>
  18. </clip>
  19. </item>
  20. </layer-list>

用您自己的蓝色代码替换颜色代码

android:startColor=”#C0C0C0″ android:centerColor=”#F8F8FF” android:endColor=”#ffffff”

猜你在找的Android相关文章