自定义进度栏如何

马丁·杜塞克(Martin Dusek)

我想创建一个带有白色背景色的自定义矩形进度条。在进度条的中心有一个文本,用于定义进度条的高度。还有另一种具有黑色背景颜色的视图,该视图的宽度从左侧开始逐渐增加,具体取决于进度。我有这个,但是不起作用:

                    <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:gravity="center"
                    android:background="#FFFFFF"   // this defines background colour
                    android:weightSum="1.0">

                    <LinearLayout // this should be aligned to the left side
                        android:layout_width="0dp"
                        android:layout_weight="0.25" // this should define percentage width
                        android:layout_height="fill_parent" // it should have height same as the TextView
                        android:background="#FF000000" />

                    <TextView
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:textColor="#FFFFFF"
                        android:textSize="40dp"
                        android:gravity="center" // it should be displayed in the center of the progress bar
                        android:text="some text"/>

在此处输入图片说明

编辑:好的,我有这个:

                    <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:background="#FFFFFFFF">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="fill_parent"
                        android:orientation="horizontal"
                        android:gravity="left"
                        android:weightSum="1.0">

                        <LinearLayout
                            android:layout_width="0dp"
                            android:layout_weight="0.25"
                            android:layout_height="fill_parent"
                            android:background="#FF000000" />
                    </LinearLayout>

                    <TextView
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:textColor="#777777"
                        android:textSize="40dp"
                        android:gravity="center"
                        android:text="@{data.remainingTime}"/>

                </RelativeLayout>

唯一的问题是:如何告诉LinearLayout与TextView一样高?

塔米尔·阿布特布尔

您可以在ConstraintLayout中使用类似的方法

  <androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/button3"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="#A496D8"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHeight_percent="0.1"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:padding="0dp"
        android:background="#000000"
        android:elevation="6dp"
        app:layout_constraintBottom_toBottomOf="@+id/button3"
        app:layout_constraintStart_toStartOf="@+id/button3"
        app:layout_constraintTop_toTopOf="@+id/button3" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:elevation="6dp"
        android:text="Some text"
        android:textAlignment="center"
        android:textColor="#000000"
        app:layout_constraintBottom_toBottomOf="@+id/button3"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="@+id/button3"
        app:layout_constraintTop_toTopOf="@+id/button3"
        app:layout_constraintVertical_bias="0.0" />

</androidx.constraintlayout.widget.ConstraintLayout>

它看起来像这样:

在此处输入图片说明

但是说实话,我认为您最好使用一些已经为您处理很多逻辑的库。例如:

NumberProgressBar

进度查看

Android-RoundCornerProgressBar


您拥有的另一个简单选择是使用水平进度条(如何创建水平加载进度条?)并在上面放置一些文本。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

自定义进度栏

来自分类Dev

Android的自定义进度栏

来自分类Dev

Android自定义圈子进度栏

来自分类Dev

创建自定义进度栏

来自分类Dev

在JS上自定义进度栏

来自分类Dev

Android自定义回合进度栏

来自分类Dev

自定义AVPlayerViewController进度栏

来自分类Dev

在JS上自定义进度栏

来自分类Dev

iOS中的自定义进度栏

来自分类Dev

自定义AVPlayerViewController进度栏

来自分类Dev

在自定义进度栏中,白色背景在Android中显示。如何删除?

来自分类Dev

如何使用指标图像(如whatsapp)制作自定义进度栏?

来自分类Dev

如何在Android的Asynk任务中使用自定义进度栏

来自分类Dev

如何在Conky中创建自己的自定义进度栏?

来自分类Dev

如何使用自定义可绘制对象设置初始评级栏进度

来自分类Dev

如何创建自定义进度

来自分类Dev

具有自定义验证的Bootstrap进度栏

来自分类Dev

自定义进度栏中的圆形渐变

来自分类Dev

具有.gif文件的Android自定义进度栏

来自分类Dev

无法更改Android中的自定义进度栏宽度

来自分类Dev

在android webview中添加自定义进度栏

来自分类Dev

进度栏自定义设计,如instagram

来自分类Dev

进度栏未在自定义启动屏幕上更新

来自分类Dev

带有标记的自定义HTML进度栏

来自分类Dev

具有.gif文件的Android自定义进度栏

来自分类Dev

使用YouTube API的自定义进度栏

来自分类Dev

具有自定义验证的Bootstrap进度栏

来自分类Dev

设置自定义进度栏时出现NoSuchMethodError

来自分类Dev

xaml带有图像的自定义进度栏