2015-07-20 50 views
5

我试图做这样的事情:背景样式不上的进度条显示

enter image description here

这是我的代码做什么:

enter image description here

我将此代码存入我的可绘制文件中:

progress_bar_layout.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 
      android:innerRadius="70dp" 
      android:shape="ring" 
      android:thickness="18dp"> 
     </shape> 
    </item> 

<item android:id="@android:id/progress"> 
    <shape 
     android:innerRadius="70dp" 
     android:shape="ring" 
     android:thickness="18dp"> 

     <gradient 
      android:endColor="#ff0f315f" 
      android:startColor="#ff005563" 
      android:type="sweep" /> 
    </shape> 
</item> 


<item android:id="@android:id/secondaryProgress"> 
    <shape 
     android:innerRadius="70dp" 
     android:shape="ring" 
     android:thickness="18dp"> 

     <gradient 
      android:endColor="#ff1490e4" 
      android:startColor="#ff00c0dd" 
      android:type="sweep" /> 
    </shape> 
</item> 

</layer-list> 

布局:

<ProgressBar 
     android:id="@+id/bar" 
     style="?android:attr/progressBarStyleHorizontal" 
     android:layout_width="180dp" 
     android:layout_height="180dp" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:max="100" 
     android:progress="99" 
     android:progressDrawable="@drawable/progress_bar_layout" 
     android:secondaryProgress="30" /> 

的问题是,我的背景风格不显示出来。这就是为什么我使用进度来完成背景的工作,但正如你所看到的,它不能很好地工作,最大尺寸是99,最后还有一个空间。我错过了一些代码?

+1

你可以上传你正在努力实现的,它可以很容易地在女士造漆或Photoshop –

+0

图像@LX已经可用。 –

+0

如果你只是想在黑色背景后面progressBar只需在你的标签中设置这个android:background =“#222222”,它将会诀窍 –

回答

3

基本上,我不得不为每个元素分割progress_bar_layout.xml可绘制文件,因此,一个文件包含进度设置,另一个文件包含进度设置。 然后,我将它们添加到相应的元素。

android:background="@drawable/circle_shape" 
android:progressDrawable="@drawable/circular_progress_bar" /> 

使用图层列表,项目没有找到背景设置,所以这种方法解决了我的问题。

circle_shape.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:innerRadius="60dp" 
    android:shape="ring" 
    android:thickness="10dp" 
    android:useLevel="false"> 

    <solid android:color="@color/blue"></solid> 

</shape> 

circular_progress_bar.xml

<?xml version="1.0" encoding="utf-8"?> 
<rotate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:fromDegrees="270" 
    android:toDegrees="270"> 
    <shape 
     android:innerRadius="60dp" 
     android:shape="ring" 
     android:thickness="10dp" 
     android:useLevel="true"> 

     <solid android:color="@color/blue"></solid> 

    </shape> 
</rotate> 
+0

你可以用circle_shape.xml和circular_progress_bar.xml的代码更新你的答案,我想看看你如何解决它 –

+0

@LX代码添加。 –