椭圆形ProgressBar紧密包裹文本

时间:2016-07-14 16:57:08

标签: android layout textview android-custom-view android-progressbar

在将其标记为重复之前,请完整阅读。这不是关于在an​​droid中创建带有文本的另一个进度条。我希望进度条大小是动态的,以覆盖文本大小。其他解决方案将一个小文本放在一个巨大的进度条中间。这应该略微覆盖它。

我试图在中心创建一个带有textview的椭圆形进度条。我希望整个进度条封装文本。所以它的宽度和高度不应该是恒定的。相反,它应该略大于textview。我试图在相对布局中封装progressbar和textview(width / height:wrap_content)。我尝试将进度条的左/右/底部/顶部与带有textview的textview加上一些负填充对齐,但是我裁剪了椭圆形进度条。这是布局文件

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

此外,我愿意接受更好/更简单的方法。

1 个答案:

答案 0 :(得分: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>