0

將其標記爲重複之前,請完整閱讀。這不是關於在an​​droid中使用文本創建另一個進度條。我希望進度條大小是動態的以覆蓋文本大小。其他解決方案在一個巨大的進度條中間放置了一個小文本。這應該稍微覆蓋它。橢圓ProgressBar緊縮文本

我正在嘗試在中心創建一個帶有textview的橢圓形進度條。我想要整個進度條來封裝文本。所以它的寬度和高度不應該是恆定的。相反,它應該比textview略大。我試圖在相對佈局中封裝progressbar和textview(width/height:wrap_content)。我嘗試使用textview加上一些負填充對齊textbar的左/右/下/頂部,但我裁剪橢圓形進度條。這裏是佈局文件

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" android:layout_height="wrap_content"> 
<ProgressBar 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/progressbar0" 
    android:layout_alignLeft="@id/txtCategoryTitle" 
    android:layout_alignRight="@id/txtCategoryTitle" 
    android:paddingLeft="-50dp" 
    android:paddingRight="-50dp" 

    android:layout_alignTop="@id/txtCategoryTitle" 
    android:layout_alignBottom="@id/txtCategoryTitle" 
    android:paddingTop="-50dp" 
    android:paddingBottom="-50dp" 

    android:indeterminate="false" 
    android:progressDrawable="@drawable/circle" 
    style="?android:attr/progressBarStyleHorizontal" 
    android:max="100" 
    android:progress="65" 
    android:layout_below="@id/clickBtn" 
    android:layout_centerInParent="true" 
    > 

</ProgressBar> 

<TextView 
    android:id="@+id/txtCategoryTitle" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="#FFFFFF" 
    android:text="MY CUSTOM TEXT" 
    android:layout_centerInParent="true" 
    android:layout_centerVertical="true" 
    android:elevation="5dp"/> 
</RelativeLayout> 

此外,我願意提供更好/更簡單的方法來做到這一點。

回答

0

沒關係, 這是一個愚蠢的做法。這裏是未來參考的新代碼

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" android:layout_height="wrap_content"> 
    <TextView 
     android:id="@+id/txtCategoryTitle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingTop="10dp" 
     android:paddingBottom="10dp" 
     android:paddingLeft="10dp" 
     android:paddingRight="10dp" 

     android:textColor="#FFFFFF" 
     android:text="MY CUSTOM TEXT" 
     android:layout_centerInParent="true" 
     android:elevation="5dp"/> 

    <ProgressBar 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@id/txtCategoryTitle" 
     android:layout_alignRight="@id/txtCategoryTitle" 
     android:layout_alignTop="@id/txtCategoryTitle" 
     android:layout_alignBottom="@id/txtCategoryTitle" 
     android:id="@+id/progressbar0" 
     android:indeterminate="false" 
     android:progressDrawable="@drawable/circle" 
     style="?android:attr/progressBarStyleHorizontal" 
     android:max="100" 
     android:progress="65" 
     > 

    </ProgressBar> 





</RelativeLayout>