首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >紧密封装文本的Oval ProgressBar

紧密封装文本的Oval ProgressBar
EN

Stack Overflow用户
提问于 2016-07-15 00:57:08
回答 1查看 122关注 0票数 0

在标记为副本之前,请仔细阅读。这不是关于在android中创建另一个带有文本的进度条。我希望进度条的大小是动态的,以涵盖文本大小。其他的解决方案是在一个巨大的进度条中间放一个小文本。这应该会略微覆盖它。

我正在尝试创建一个中间有文本视图的椭圆形进度条。我想要整个进度条来封装文本。所以它的宽度和高度不应该是常数。相反,它应该比文本视图稍大一些。我试图将进度栏和文本视图(width/height:wrap_content)封装在一个相对的布局中。我试着用文本视图和文本视图对齐进度条的左/右/底/顶,再加上一些负边距,但我裁剪了椭圆形进度条。这是布局文件

代码语言:javascript
复制
<?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>

此外,我也乐于接受更好/更简单的方法的建议。

EN

回答 1

Stack Overflow用户

发布于 2016-07-15 01:43:37

不要紧,这是一个愚蠢的方法。下面是供将来参考的新代码

代码语言:javascript
复制
<?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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38380039

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档