用这个:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<View
android:layout_height="2dp"
android:layout_width="50dp"
android:background="#000"
android:layout_gravity="center"/>
<TextView
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="or"
android:layout_gravity="center"/>
<View
android:layout_height="2dp"
android:layout_width="50dp"
android:background="#000"
android:layout_gravity="center"/>
</LinearLayout>
您可以更改layout_width
的View
设置线的大小,颜色等。
这是输出:
试试这个那个特定部分
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<View
android:layout_width="200dp"
android:layout_height="1dp"
android:background="#c4c8c9"
android:layout_margin="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="or"
/>
<View
android:layout_width="200dp"
android:layout_height="1dp"
android:background="#c4c8c9"
android:layout_margin="5dp" />
</LinearLayout>
试试这个方式,它为我工作
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
>
<View
android:layout_width="50dp"
android:layout_height="1dp"
android:background="@android:color/holo_red_dark"
android:layout_gravity="center_vertical"
/>
<TextView android:text="Or" android:layout_width="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_height="wrap_content" />
<View
android:layout_width="50dp"
android:layout_height="1dp"
android:background="@android:color/holo_red_dark"
android:layout_gravity="center_vertical"
/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/forgot_password"
>
<View
android:layout_width="fill_parent"
android:layout_height="0.75dp"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/tv_1"
android:layout_marginLeft="50dp"
android:background="#cecece" />
<TextView
android:id="@+id/tv_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="OR"
android:textColor="#696969"
android:textSize="13sp" />
<View
android:layout_width="fill_parent"
android:layout_height="0.75dp"
android:layout_marginRight="50dp"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/tv_1"
android:background="#cecece" />
</RelativeLayout>
我希望它会很有用
您可以使用此单的TextView做工精细
<TextView
android:drawablePadding="10dp"
android:drawableLeft="@drawable/seprator_line.png"
android:drawableRight="@drawable/seprator_line.png"/>
我希望这帮助。
下面是我会做,
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E73A4A">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="16dp">
<View
android:layout_width="200dp"
android:layout_height="2dp"
android:layout_centerInParent="true"
android:background="#F6828F" />
<TextView
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#E73A4A"
android:text="or"
android:textAlignment="center"
android:textColor="#F6828F" />
</RelativeLayout>