0

I have a design requirement to show a part as shown in the figure.Example Image

I have tried the following XML

<LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >

                <View
                android:id="@+id/lineLeft"
                android:layout_height="1dip"
                android:layout_width="25dp"
                android:layout_marginBottom="10dp"
                android:background="#b8b8b8" />

                <TextView
                    android:id="@+id/link_to_register"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="40dip"
                    android:layout_marginTop="40dip"
                    android:gravity="center"
                    android:text="@string/register_label"
                    android:textColor="#525252"
                    android:textSize="20sp" />

                <View
                android:id="@+id/lineRight"
                android:layout_height="1dip"
                android:layout_width="25dp"
                android:layout_marginBottom="10dp"
                android:background="#b8b8b8" />

            </LinearLayout>

The above XML shows the TextView, but not the lines. How can I achieve it.

Please help.

openrijal
  • 583
  • 6
  • 22
  • Do u want your left line, TextView and right line aligned centered vertically. or u want it just like the way you have in the image of your question.? – SKK May 23 '13 at 13:26

2 Answers2

4

Try this out:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <View
        android:id="@+id/lineLeft"
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_margin="10dp"
        android:layout_weight="1"
        android:background="#b8b8b8" />

    <TextView
        android:id="@+id/link_to_register"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="register_label"
        android:textColor="#525252"
        android:textSize="20sp" />

    <View
        android:id="@+id/lineRight"
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_margin="10dp"
        android:layout_weight="1"
        android:background="#b8b8b8" />
</LinearLayout>
SKK
  • 5,261
  • 3
  • 27
  • 39
0

Try this:

<RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal" >

            <View
            android:id="@+id/lineLeft"
            android:layout_height="1dip"
            android:layout_width="25dp"
            android:layout_marginBottom="10dp"
            android:background="#b8b8b8" />

            <TextView
                android:id="@+id/link_to_register"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:text="@string/register_label"
                android:textColor="#525252"
                android:textSize="20sp" />

            <View
            android:id="@+id/lineRight"
            android:layout_height="1dip"
            android:layout_width="25dp"
            android:layout_marginBottom="10dp"
            android:background="#b8b8b8" />

        </RelativeLayout>

You could also replace layout_centerInParent with layout_centerHorizontal to get the text in the center top.

TronicZomB
  • 8,667
  • 7
  • 35
  • 50