0

I have a relative layout like below,when I hardcoded the RelativeLayout height to 25dp,it have no problem,it shown like image below.

enter image description here

What I want is,when the red horizontal line can expand the height automatically when the TextView become multiple line,but not hardcoded height.

Here is my code

   <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <View
        android:id="@+id/line"
        android:layout_width="3dp"
        android:layout_height="match_parent"
        android:background="@color/blue" />

    <TextView
        android:id="@+id/TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginLeft="4dp"
        android:layout_marginStart="4dp"
        android:layout_toEndOf="@+id/line"
        android:layout_toRightOf="@+id/line"
        android:text="TextView"
        android:textColor="@color/black"
        android:textSize="14sp" />
</RelativeLayout>

When I change RelativeLayout height to wrap_content,the vertical line become invisible.

So my question is,how to make a vertical line which height can be expandable depend on height of TextView ?

ken
  • 2,426
  • 5
  • 43
  • 98
  • 1
    check this https://stackoverflow.com/questions/15128652/how-to-add-vertical-divider-to-a-horizontal-linearlayout – AskNilesh Sep 25 '17 at 06:17

2 Answers2

2

You can use a horizontal linear layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <View
        android:id="@+id/line"
        android:layout_width="13dp"
        android:layout_height="match_parent"
        android:background="@color/md_blue_900" />

    <TextView
        android:id="@+id/TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginLeft="4dp"
        android:layout_marginStart="4dp"
        android:text="TextView"
        android:textColor="@color/md_black_1000"
        android:textSize="14sp" />
</LinearLayout>
Adolf Dsilva
  • 13,092
  • 8
  • 34
  • 45
0

Below Code Works for me

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
    <View
        android:id="@+id/line"
        android:layout_width="3dp"
        android:layout_height="match_parent"
        android:background="#cd2121" />

    <TextView
        android:id="@+id/TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginLeft="4dp"
        android:layout_marginStart="4dp"
        android:text="TextView \n tegdienaifa \n nfuyeuayeyae \n tefgaeyigufYK"
        android:textSize="14sp" />
</LinearLayout>
Geeta Gupta
  • 1,622
  • 11
  • 17