如何在 android 中绘制 <hr> 像中间带有文本的线

how to draw <hr> like line with text in the middle in android

我正在尝试创建以下布局:有一条 hr 样式线,我知道如何制作它,但我无法将文本 (OR) 放在上面它,同样创建两个 hr 行,使用相对布局似乎不可能在中间显示文本。关于如何完成此操作的任何提示?

您可以在没有任何线条可绘制对象的情况下执行此操作。

对于 "OR" 两边的线条,只需制作高度为 1(或任何你想要的厚度)的视图,以及你想要的背景颜色并适当放置它们。

试试以下方法:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="5dp">

    <Button android:id="@+id/signInButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:background="#ff0000"
        android:textStyle="bold"
        android:textColor="#ffffff"
        android:text="SIGN IN WITH GOOGLE"/>

    <TextView android:id="@+id/or"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/signInButton"
        android:layout_centerHorizontal="true"
        android:textColor="#777777"
        android:text="OR"
        android:layout_marginTop="15dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp" />

    <View android:id="@+id/leftLine"
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:background="#777777"
        android:layout_alignLeft="@id/signInButton"
        android:layout_toLeftOf="@id/or"
        android:layout_alignTop="@id/or"
        android:layout_marginTop="7dp"/>

    <View android:id="@+id/rightLine"
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:background="#777777"
        android:layout_toRightOf="@id/or"
        android:layout_alignRight="@id/signInButton"
        android:layout_alignTop="@id/or"
        android:layout_marginTop="7dp"/>    

</RelativeLayout>