0

Bevor Sie es als Duplikat markieren, lesen Sie es bitte vollständig. Es geht nicht darum, einen weiteren Fortschrittsbalken mit Text in Android zu erstellen. Ich möchte, dass die Größe des Fortschrittsbalkens dynamisch ist, um die Textgröße abzudecken. Die anderen Lösungen setzen einen kleinen Text in die Mitte einer riesigen Fortschrittsleiste. Dies sollte etwas abdecken.Oval ProgressBar ENTSPANNUNG ENTSPRECHEND Text

Ich versuche, ovale Fortschrittsbalken mit einer Textansicht in der Mitte zu erstellen. Ich möchte, dass die ganze Fortschrittsleiste den Text einkapselt. Breite und Höhe sollten also nicht konstant sein. Stattdessen sollte es etwas größer als die Textansicht sein. Ich habe versucht, Fortschrittsbalken und die Textansicht (width/height: wrap_content) in einem relativen Layout zu kapseln. Ich habe versucht, links/rechts/unten/oben von Fortschrittsbalken mit Textansicht mit Textansicht plus einige negative Polsterung ausrichten, aber ich schneidet die ovale Fortschrittsleiste. Hier ist die Layoutdatei

<?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> 

Auch ich bin offen für Vorschläge für bessere/einfachere Möglichkeiten, dies zu tun.

Antwort

0

Macht nichts, Es war ein dummer Ansatz. Hier ist der neue Code für zukünftige Referenz

<?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>