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> 

然後,我手動計算進度並以編程方式設置「進度線」的寬度。