How do I add a vertical separator line between 3 d

2019-04-17 07:31发布

问题:

I have 3 values displayed consecutively on the screen and I need to add 2-3 vertical separator lines between all of them.The issue is everytime I add a view/ divider between them they shift to the left or right way too much and some values cut off/ disappear. I was wondering if there is a way to go abotu it, below is my xml code for the same:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:foo="http://schemas.android.com/apk/res/com.justin.abc"
    android:layout_width="20dp"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:paddingBottom="8dp"
    android:paddingLeft="20dp"
    android:paddingTop="8dp" >

    <LinearLayout
        android:id="@+id/layout1"
        android:layout_width="2dp"
        android:layout_height="match_parent"
        android:orientation="vertical" >

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

            <com.justin.abc.utils.FontView
                android:id="@+id/symbol"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingRight="3dp"
                android:textColor="@color/white"
                android:textSize="12sp"
                foo:customFont="Roboto-Bold.ttf" />

            <com.justin.abc.utils.FontView
                android:id="@+id/arrow"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="14sp"
                foo:customFont="Roboto-Bold.ttf" />
        </LinearLayout>

        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/value1_back"
                style="@style/abc.TextView.ListsTextView.Header"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:padding="3dp"/>

            <com.justin.abc.utils.FontView
                android:id="@+id/change"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="15sp"
                foo:customFont="Roboto-Bold.ttf" />
        </FrameLayout>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/layout2"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:orientation="vertical" >

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

            <com.justin.abc.utils.FontView
                android:id="@+id/symbol2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingRight="3dp"
                android:textColor="@color/white"
                android:textSize="12sp"
                foo:customFont="Roboto-Bold.ttf" />

            <com.justin.abc.utils.FontView
                android:id="@+id/dashboard_markets_arrow2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="14sp"
                foo:customFont="Roboto-Bold.ttf" />
        </LinearLayout>

        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/value2_back"
                style="@style/abc.TextView.ListsTextView.Header"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:padding="3dp"/>

            <com.justin.abc.utils.FontView
                android:id="@+id/change2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="15sp"
                foo:customFont="Roboto-Bold.ttf" />
        </FrameLayout>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/layout3"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:orientation="vertical" >

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

            <com.justin.abc.utils.FontView
                android:id="@+id/dashboard_markets_symbol3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingRight="3dp"
                android:textColor="@color/white"
                android:textSize="12sp"
                foo:customFont="Roboto-Bold.ttf" />

            <com.justin.abc.utils.FontView
                android:id="@+id/dashboard_markets_arrow3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="14sp"
                foo:customFont="Roboto-Bold.ttf" />
        </LinearLayout>

        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/value3_back"
                style="@style/abc.TextView.ListsTextView.Header"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:padding="3dp"/>

            <com.justin.abc.utils.FontView
                android:id="@+id/change3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="15sp"
                foo:customFont="Roboto-Bold.ttf" />
        </FrameLayout>
    </LinearLayout>

</LinearLayout>

Do I need to add a layer or something in the background for it to support the same or do I need to change this structure? Thanks! Justin

even after adding android:gravity="center" I still see the same results

回答1:

As @Gru says, you can get the black line using a View between layout1 and layout2 and layout2 and layout3.

As you point out, this will be on the left edge of the contents of layout2 and layout3. To separate this out a bit, an easy solution is to add the line:

android:paddingLeft="20dp"

to layout1, layout2 and layout3, whilst removing it from the top LinearLayout. This won't achieve precise centring, but it will give an equal text to left edge for each block, which I think will look about right.



回答2:

Place this in between each value you have mentioned in your question.

<View android:layout_height="fill_parent" android:layout_width="2px" android:background="#000000"/>

should give you a black bar in between values.