2017-06-16 112 views
1

我可以在Android中更改ProgressBar中的“进度线”的高度,因此它大于“背景线”以实现此效果吗?如何更改进度条中“进度线”的高度?

what I want to achieve!!!

我曾尝试在后台设置大小和我的自定义progressBarDrawable进步项目,但似乎并没有工作。

<ProgressBar 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:indeterminate="false" 
      android:max="100" 
      android:progress="50" 
      android:paddingTop="10dp" 
      android:paddingBottom="10dp" 
      android:progressDrawable="@drawable/xml_progress_bar_line" 
      style="@style/Widget.AppCompat.ProgressBar.Horizontal"/> 

这里是xml_progress_bar_line.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> 
      <size 
       android:height="5dp"/> 
      <solid 
       android:color="@color/grey" /> 
     </shape> 
    </item> 

    <item 
     android:id="@android:id/progress"> 
     <clip> 
      <shape> 
       <size 
        android:height="10dp"/> 
       <solid 
        android:color="@color/green" /> 
       <corners 
        android:radius="10dp"/> 
      </shape> 
     </clip> 
    </item> 
</layer-list> 

回答

0

我结束了不使用在进度条所有!

我刚刚在相对布局中使用了2行。这是相应的代码!

这里是进度条背景线XML(xml_custom_progress_bar_bg.xml):

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 

    <corners 
     android:radius="4dp"/> 
    <solid 
     android:color="@color/light_grey"/> 

</shape> 

这里是进度条 “进度线” XML(xml_custom_progress_bar_progress.xml):

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 

    <corners 
     android:radius="4dp"/> 
    <gradient 
     android:angle="270" 
     android:startColor="@color/green" 
     android:endColor="@color/green"/> 

</shape> 

这里是进度条容器:

<RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <View 
      android:layout_width="match_parent" 
      android:layout_height="4dp" 
      android:layout_centerVertical="true" 
      android:background="@drawable/xml_custom_progress_bar_bg"/> 

     <View 
      android:layout_width="0dp" 
      android:layout_height="8dp" 
      android:layout_centerVertical="true" 
      android:background="@drawable/xml_custom_progress_bar_progress"/> 

    </RelativeLayout> 

然后,我手动计算进度并以编程方式设置“进度线”的宽度。