在标记为副本之前,请仔细阅读。这不是关于在android中创建另一个带有文本的进度条。我希望进度条的大小是动态的,以涵盖文本大小。其他的解决方案是在一个巨大的进度条中间放一个小文本。这应该会略微覆盖它。
我正在尝试创建一个中间有文本视图的椭圆形进度条。我想要整个进度条来封装文本。所以它的宽度和高度不应该是常数。相反,它应该比文本视图稍大一些。我试图将进度栏和文本视图(width/height:wrap_content)封装在一个相对的布局中。我试着用文本视图和文本视图对齐进度条的左/右/底/顶,再加上一些负边距,但我裁剪了椭圆形进度条。这是布局文件
<?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>此外,我也乐于接受更好/更简单的方法的建议。
发布于 2016-07-15 01:43:37
不要紧,这是一个愚蠢的方法。下面是供将来参考的新代码
<?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>https://stackoverflow.com/questions/38380039
复制相似问题