2014-03-04 114 views

回答

22

我看到很多人都在寻找这个后,所以我想我应该编辑和分享一个例子:

注(这个例子是不完整的,这是仍在进行中,但我想这是一个起点)

GitHub上:Github Example

enter image description here

在这个例子中最重要的部分是如下: 创建绘制一个xml文件custom_progress_bar_horizo​​ntal.xml并添加下面的内容。

<?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> 
      <padding 
       android:bottom="3dip" 
       android:top="3dip" 
       android:left="3dip" 
       android:right="3dip"/> 
      <corners 
       android:radius="5dip" /> 
      <gradient 
       android:startColor="#2a2b2f" 
       android:centerColor="#2a2b2f" 
       android:centerY="0.50" 
       android:endColor="#2a2b2f" 
       android:angle="270" /> 
     </shape> 
    </item> 
    <item 
     android:id="@android:id/progress"> 
     <clip> 
      <shape> 
       <corners 
        android:radius="5dip" /> 
       <gradient 
        android:startColor="#ff0e75af" 
        android:endColor="#ff1997e1" 
        android:angle="90" /> 
      </shape> 
     </clip> 
    </item> 
</layer-list> 

添加以下代码在styles.xml

<style name="CustomProgressBar" parent="android:Widget.ProgressBar.Horizontal"> 
    <item name="android:indeterminateOnly">false</item> 
    <item name="android:progressDrawable">@drawable/custom_progress_bar_horizontal</item> 
    <item name="android:minHeight">10dip</item> 
    <item name="android:maxHeight">20dip</item> 
</style> 

你已经在你的活动布局添加样式后添加:

<ProgressBar 
     android:id="@+id/customProgress" 
     style="@style/CustomProgressBar" 
     android:layout_width="match_parent"/> 

dispaly低于一帧中取得进展,是一个有点棘手,因为您需要扩展ProgressBar类并在那里进行更改。

我会在这里留下一些例子,并通知我何时将它们添加到我的github项目中。

如果你想disaply你的方式进步

很好的例子: NumberProgressBar

其它进度条的例子:

Custom progress bar 1

Custom progress bar 2

Custom progress bar 3

更新:

也检查DiscreteSeekBar这是一个伟大的github项目。

摇篮:编译 'org.adw.library:离散搜索条:1.0.1'

干杯,

+1

我搜索了这个话题,得到了这个职位。 :) – level32