Android 中的进度条和文本 [英] Progressbar along with text in Android

查看:35
本文介绍了Android 中的进度条和文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建 ProgressBar 以及与下面相同的文本.

I would like to create ProgressBar along with text same as below.

请指导我.我开发了一些设计,但我无法在 ProgressBar 的右侧显示文本,因为进度条采用最小宽度.请看下图:

Please guide me. I developed some design but I am not able to display text exactly right side of ProgressBar as progress bar take min width. Please see below image:

我被困在这个问题上.提前致谢.

I am stuck on this. Thanks in advance.

我的代码是:

 <RelativeLayout
            android:layout_width="match_parent"
            android:layout_below="@+id/lnrButtons"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_marginRight="30dp"
            android:padding="5dp"
            android:background="@drawable/white_button_selector">

            <ProgressBar
                android:id="@+id/progressBarHome"
                android:layout_width="match_parent"
                style="?android:attr/progressBarStyleHorizontal"
                android:progressDrawable="@drawable/custom_progress_bar"
                android:layout_height="wrap_content"
                android:progress="50"
                android:layout_alignParentStart="true"
                android:layout_centerVertical="true"
                android:indeterminate="false"/>

            <TextView
                android:id="@+id/txtProgress"
                android:layout_width="wrap_content"
                android:text="10%"
                android:textColor="@color/light_orange"
                android:background="@android:color/transparent"
                android:layout_centerVertical="true"
                android:layout_alignRight="@+id/progressBarHome"

                android:layout_height="wrap_content"/>

        </RelativeLayout>

执行代码更改后输出为:

After implementing code changes output is:

推荐答案

你只是按照那个设计布局.我认为你的布局设计会跟随.

You just design the layout according to that.I think your layout design will be following.

例如.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <ProgressBar
      style="@android:style/Widget.ProgressBar.Horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
       android:id="@+id/PROGRESS_BAR"
    >
    <TextView
        android:background="#00000000" // transparent background
        android:layout_alignLeft="@id/PROGRESS_BAR"
        android:layout_alignTop="@id/PROGRESS_BAR"
        android:layout_alignRight="@id/PROGRESS_BAR"
        android:layout_alignBottom="@id/PROGRESS_BAR"
    >
</RelativeLayout>

根据您的要求,如果您想移动文本视图,您必须将进度值传递给以下 txtView.setX((int) ur progress value);

As per your requirement if you want to move your textview you have to pass your progress value to the following txtView.setX((int) ur progress value);

希望能帮到你.

这篇关于Android 中的进度条和文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆