How to draw a vertical separation line between two android text strings?

I use two horizontal lines of view (id - view2 and view 3) between the top and bottom of the relative layout. How to place a vertical viewing line between two texts. Here is the code and a screenshot of the expected result.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<RelativeLayout
    android:id="@+id/delivery_address"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/address_layout"
    android:layout_margin="10dp"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/delivery_phone"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/delivery_country"
        android:layout_marginLeft="7dp"
        bold=""
        android:paddingLeft="6dp"
        android:paddingTop="5dp"
        android:text="Phone: 12345678
        android:textStyle=" />
</RelativeLayout>

<View
    android:id="@+id/view2"
    android:layout_width="wrap_content"
    android:layout_height="1dp"
    android:layout_below="@+id/delivery_address"
    android:layout_centerVertical="true"
    android:background="#cfcfcf" />

<RelativeLayout
    android:id="@+id/delivery_edit_delete_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/view2"
    android:layout_margin="8dp"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/delivery_edit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="7dp"
        android:drawableLeft="@drawable/delivery_edit"
        android:drawablePadding="5dp"
        android:paddingLeft="20dp"
        android:text="Edit"
        android:textColor="#555555" />

    <TextView
        android:id="@+id/delivery_delete"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginRight="7dp"
        android:layout_toLeftOf="@+id/delivery_edit"
        android:drawableLeft="@drawable/delivery_delete"
        android:drawablePadding="5dp"
        android:paddingRight="20dp"
        android:text="Delete"
        android:textColor="#555555" />
</RelativeLayout>

<View
    android:id="@+id/view3"
    android:layout_width="wrap_content"
    android:layout_height="1dp"
    android:layout_below="@+id/delivery_edit_delete_layout"
    android:layout_centerVertical="true"
    android:background="#cfcfcf" />

Expected Result:

enter image description here

My output is:

enter image description here

+4
source share
6 answers

What will i do:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout     xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

    <RelativeLayout
    android:id="@+id/delivery_address"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/address_layout"
    android:layout_margin="10dp"
     android:orientation="horizontal" >

        <TextView
        android:id="@+id/delivery_phone"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/delivery_country"
        android:layout_marginLeft="7dp"
        android:paddingLeft="6dp"
        android:paddingTop="5dp"
        android:text="Phone: 12345678
        android:textStyle="bold" />
    </RelativeLayout>

    <View
    android:id="@+id/view2"
    android:layout_width="wrap_content"
    android:layout_height="1dp"
    android:layout_below="@+id/delivery_address"
    android:layout_centerVertical="true"
    android:background="#cfcfcf" />

    <RelativeLayout
    android:id="@+id/delivery_edit_delete_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/view2"
    android:orientation="horizontal" >

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

            <TextView
            android:id="@+id/delivery_edit"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_gravity="center" (Or try android:gravity)
            android:layout_marginLeft="7dp"
            android:drawableLeft="@drawable/delivery_edit"
            android:drawablePadding="5dp"
            android:paddingLeft="20dp"
            android:text="Edit"
            android:textColor="#555555" />

            <View
            android:id="@+id/innerLine"
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#cfcfcf" />

            <TextView
            android:id="@+id/delivery_delete"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_gravity="center" (Or try android:gravity)
            android:layout_marginRight="7dp"
            android:layout_toLeftOf="@+id/delivery_edit"
            android:drawableLeft="@drawable/delivery_delete"
            android:drawablePadding="5dp"
            android:paddingRight="20dp"
            android:text="Delete"
            android:textColor="#555555" />

        </LinearLayout>
    </RelativeLayout>

    <View
    android:id="@+id/view3"
    android:layout_width="wrap_content"
    android:layout_height="1dp"
    android:layout_below="@+id/delivery_edit_delete_layout"
    android:layout_centerVertical="true"
    android:background="#cfcfcf" />
</RelativeLayout>

Try using LinearLayout, because it will be right in the middle of two. Hope this piece of code helps! I have not tried this yet, so you should check it out for me!

: , ( layout_gravity/gravity , android: gravity LinearLayout).

+5

. , drawables, textview sttyle:

//your textview
<TextView android:text="Hi there" android:background="@drawable/my_border/>

drawable/my_border:

//you can set the border colors, width, and which sides should have borders.
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
  <solid android:color="#ffffff" />
  <stroke android:width="1dip" android:color="#e2e2e2"/>
</shape>

/ , :

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    //this is your textview main background
    <shape android:shape="rectangle">
        <solid android:color="#ffffff" />
    </shape>
</item>
//this will then draw only left border with specified colour and width
<item android:left="1dp">
    <shape android:shape="rectangle">
        <solid android:color="#e1e1e1" />
    </shape>
</item>

0

RelativeLayout, delivery_edit_delete_layout delivery_edit:

<View
android:id="@+id/view_separator"
android:layout_width="1dp"
android:layout_height="30dp"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:background="#cfcfcf" />

, , 30dp RelativeLayout match_parent.

0

, , .
, .
- , .

, , .

     <LinearLayout
        android:id="@+id/delivery_edit_delete_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/view2"
        android:layout_margin="8dp"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/delivery_edit"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:drawableLeft="@drawable/delivery_edit"
            android:gravity="center"
            android:layout_weight="1"
            android:text="Edit"
            android:textColor="#555555" />

        <View
            android:id="@+id/verticalLine"
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#cfcfcf" >
        </View>

        <TextView
            android:id="@+id/delivery_delete"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:drawableLeft="@drawable/delivery_delete"
            android:gravity="center"
            android:text="Delete"
            android:textColor="#555555" />
    </LinearLayout>
0

enter image description here

<LinearLayout
        android:id="@+id/delivery_edit_delete_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/view2"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/delivery_edit"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="7dp"
            android:layout_weight="1"
            android:background="@drawable/divider"
            android:drawableLeft="@drawable/delivery_edit"
            android:drawablePadding="5dp"
            android:gravity="center"
            android:paddingLeft="20dp"
            android:text="Edit"
            android:textColor="#555555" />

        <TextView
            android:id="@+id/delivery_delete"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="7dp"
            android:layout_weight="1"
            android:drawableLeft="@drawable/delivery_delete"
            android:drawablePadding="5dp"
            android:gravity="center"
            android:paddingRight="20dp"
            android:text="Delete"
            android:textColor="#555555" />
    </LinearLayout>

divider.xml ur drawables

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item
    android:bottom="-2dp"
    android:left="-2dp"
    android:right="1dp"
    android:top="-2dp">
    <shape android:shape="rectangle" >
        <stroke
            android:width="1dp"
            android:color="#cfcfcf" />

        <solid android:color="@android:color/transparent" />

        <padding
            android:bottom="10dp"
            android:left="10dp"
            android:right="10dp"
            android:top="10dp" />
    </shape>
</item>
</layer-list>

, u...

0

.

<View
   android:layout_width="wrap_content"
   android:layout_height="1dp"
   android:background="#979797"/>
0

All Articles