Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Horizontal lines on either sides of TextView

Can't figure out a way to have a centered TextView with vertically centered horizontal lines on either sides, stretched to the left and right end of the screen. Like on this picture below.

That's what I'm talking about

Any insight would help!

like image 495
Leo Avatar asked Jan 23 '26 11:01

Leo


2 Answers

Finally came up with this solution that does exactly what is required

    <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="24dp"
            >

        <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="@color/light_grey"
                android:layout_gravity="center_vertical"/>

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/add_heading_description"
                android:textSize="@dimen/add_headings"
                android:textColor="@color/dark_grey"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:layout_gravity="center"
                android:background="@color/white"
                />

    </FrameLayout>
like image 198
Leo Avatar answered Jan 25 '26 02:01

Leo


I am having problem with the accepted answer, so sharing my way:

 <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="0dp"
            android:orientation="horizontal">

            <View
                android:layout_width="40dp"
                android:layout_height="1dp"
                android:background="@color/secondary_text"
                android:layout_gravity="center_vertical"
                android:layout_weight="1"/>

            <Button
                android:layout_width="20dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@null"
                android:text="@string/Or"
                android:clickable="false"
                android:textColor="@color/secondary_text" />

            <View
                android:layout_width="40dp"
                android:layout_height="1dp"
                android:background="@color/secondary_text"
                android:layout_gravity="center_vertical"
                android:layout_weight="1"/>

        </LinearLayout>

enter image description here

like image 42
Puneet Kushwah Avatar answered Jan 25 '26 00:01

Puneet Kushwah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!