【问题标题】:How to make an horizontal ProgressBar match a TextView size如何使水平 ProgressBar 与 TextView 大小匹配
【发布时间】:2015-04-30 19:37:42
【问题描述】:

我希望我的 ProgressBar 与我的 TextView 的大小相匹配,以便根据我在 TextView 中所写的内容使其更短或更长。

这是我的 XML:

<LinearLayout
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerVertical="true"
      android:layout_toRightOf="@+id/iv_file_icon"
      android:orientation="vertical" >
      <TextView
          android:id="@+id/tv_file"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textStyle="bold"
          android:textSize="22sp"
          android:text="Filename" />
      <ProgressBar
          android:id="@+id/pb_file"
          style="?android:attr/progressBarStyleHorizontal"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:max="100"
          android:minWidth="200dp"
          android:progress="0"
          android:visibility="gone"/>
</LinearLayout>

【问题讨论】:

    标签: android xml textview android-progressbar


    【解决方案1】:

    在我看来,您可以尝试使用其他布局,例如 RelativeLayout :

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="Text I want to display" />
    
       <ProgressBar
           android:id="@+id/pb_file"
           style="?android:attr/progressBarStyleHorizontal"
           android:layout_width="match_parent"
           android:layout_height="20dp"
           android:layout_alignLeft="@+id/textView1"
           android:layout_alignRight="@+id/textView1"
           android:layout_below="@+id/textView1"
           android:layout_marginTop="23dp"
           android:max="100"
           android:progress="0" />
    
    </RelativeLayout>
    

    【讨论】:

      猜你喜欢
      • 2021-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-01
      • 2012-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多