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
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>