how to set width which is equal to another widget on android

前端 未结 7 419
走了就别回头了
走了就别回头了 2021-02-03 19:27

I need to draw a horizontal line below a text field such that the width of the line equals the text width (not the width of the full screen).

In my app I have a textview

相关标签:
7条回答
  • 2021-02-03 20:05

    If you don't want to use RelativeLayout then you can set parent's width to wrap content and parent's width will become equal to biggest child. Then you can set the width of the small child to match_parent and it'll match the width of required view.

      <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:gravity="center_vertical|left"
            android:orientation="vertical"
            android:layout_gravity="center_vertical"
            android:padding="5dp">
    
            <TextView
                android:id="@+id/navHeaderName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_above="@+id/profile_progress_bar"
                android:text="This is a large text"
                android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
    
    
            <ProgressBar
                android:id="@id/profile_progress_bar"
                style="?android:attr/progressBarStyleHorizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:max="100"
                android:progress="45" />
        </LinearLayout>
    
    0 讨论(0)
提交回复
热议问题