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