How to place a text between two straight line android?

假装没事ソ 提交于 2020-01-16 04:54:06

问题


I need to place a text between a straight line. I tried by using view but textview comes below the line. How to solve this? My code is as follows:

   <RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"

 >
<View

         android:layout_width="wrap_content"
         android:layout_height="2dp"
         android:layout_alignParentLeft="true"
         android:layout_toLeftOf="@+id/orText"
         android:background="#c0c0c0"/>
 <View
         android:layout_width="wrap_content"
         android:layout_height="2dp"
         android:background="#c0c0c0"
         android:layout_toRightOf="@+id/orText"
         android:layout_alignParentRight="true"/>

 <TextView
     android:id="@+id/orText"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentTop="true"
     android:layout_centerHorizontal="true"
     android:text="OR"
     android:textColor="@android:color/black" />

 </RelativeLayout>

Here is screenshot,


回答1:


<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal"
        android:layout_marginTop="10dp" >

        <View
            android:layout_width="wrap_content"
            android:layout_height="2dp"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@+id/orText"
            android:background="#c0c0c0" />

        <TextView
            android:id="@+id/orText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:text="OR"
            android:textColor="@android:color/black" />

        <View
            android:layout_width="wrap_content"
            android:layout_height="2dp"
            android:layout_centerVertical="true"
            android:layout_toLeftOf="@+id/orText"
            android:background="#c0c0c0" />
    </RelativeLayout>



来源:https://stackoverflow.com/questions/27293827/how-to-place-a-text-between-two-straight-line-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!