How can I create a vertical line with fixed height in Android XML?

android horizontal line drawable
android:divider
vertical dotted line android
android draw dashed line programmatically
how to draw a vertical line in android programmatically
android divider line layout
android:shape=line bottom
how to draw a line in android studio

Wanted to create a UI like in this picture, I tried View with background in relative layout , which doesn't work for fixed height, what is the best way to build the left red vertical line in the UI given below ?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f5f5f5"
android:orientation="vertical"
tools:ignore="MissingPrefix">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#a9382b">

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

        <ImageView
            android:layout_marginLeft="14dp"
            android:layout_marginTop="14dp"
            android:layout_marginBottom="14dp"
            android:layout_marginRight="9dp"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:src="@drawable/globe"/>

        <TextView
            android:layout_marginTop="9dp"
            android:layout_weight="7"
            android:layout_marginBottom="9dp"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:textSize="13sp"
            android:textColor="#b3ffffff"
            fontPath="fonts/montserrat-medium.ttf"
            android:letterSpacing="-0.03"
            android:lineSpacingExtra="2sp"
            tools:text="Farmer Suicides, Agitations The Indian Agrarian 
    Crisis"
            />

        <LinearLayout
            android:layout_weight="3"
            android:layout_width="0dp"
            android:layout_marginRight="16dp"
            android:layout_height="wrap_content">
        <Button
            android:layout_width="87dp"
            android:layout_height="32dp"
            android:background="@drawable/button"
            android:text="FOLLOW"
            android:textColor="#FFFFFF"
            fontPath="fonts/montserrat-medium.ttf"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp"
            android:layout_marginLeft="12dp"
            android:textSize="12sp"
            android:lineSpacingExtra="0sp"
            android:gravity="center_horizontal||center_vertical"
            />
        </LinearLayout>



    </LinearLayout>



</RelativeLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="0dp"
    android:layout_marginTop="17dp"
    android:layout_marginLeft="15dp">

    <LinearLayout
        android:layout_gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_marginRight="15dp">

    <ImageView
        android:layout_gravity="center"
        android:layout_width="10dp"
        android:layout_height="10dp"
      android:background="@drawable/ic_radio_button_unchecked_black_24dp"
        />


    </LinearLayout>



<TextView
    android:layout_gravity="center"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="13sp"
    android:textColor="#757575"
    android:letterSpacing="-0.03"
    android:lineSpacingExtra="0sp"
    tools:text="8 hours ago"
    />

</LinearLayout>

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

    <view
        android:layout_width="2dp"
        android:layout_height="match_parent"
        android:layout_marginLeft="19dp"
        android:background="#a9382b"
        android:layout_marginRight="19dp"/>

    <ImageView
        android:layout_marginTop="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginRight="20dp"
        android:src="@drawable/background_splash" />

</LinearLayout>

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

    <view
        android:layout_width="2dp"
        android:layout_alignParentTop="true"
        android:layout_height="wrap_content"
        android:layout_marginLeft="19dp"
        android:background="#a9382b" />

    <TextView
        android:id="@+id/seeall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="20dp"
        android:textColor="#a9382b"
        android:textSize="11sp"
        tools:text="SEE ALL" />

    <TextView
        android:id="@+id/articles"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="10dp"
        android:layout_toLeftOf="@id/seeall"
        android:textColor="#757575"
        android:textSize="11sp"
        tools:text="7 Articles"

        />


</RelativeLayout>

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

    <View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="20dp"
        android:background="#a9382b"/>

</LinearLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="15dp">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_alignParentLeft="true"
        android:layout_centerInParent="true"
        android:layout_marginRight="15dp">


        <ImageView
            android:layout_gravity="center"
            android:layout_width="10dp"
            android:layout_height="10dp"
            android:background="@drawable/ic_add_circle_outline_black_24dp"
            />

    </LinearLayout>

    <TextView
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:id="@+id/view_more"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="11sp"
        android:textColor="#a9382b"
        android:layout_marginRight="20dp"
        android:layout_alignParentRight="true"
        android:gravity="end"
        tools:text="VIEW FULL STORY"
        android:layout_marginTop="15dp"

        />




</RelativeLayout>



</LinearLayout>

You can try by two answer

1) You can create the view

 <View
                android:layout_width="1dp"
                android:layout_height="50dp" 
                android:background="#cdcdcd" />

2) You can create the linear layout and set the left margin color for the linear layout , for this follow the below method.

Create this xml file under the drawable folder margin_color.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">


<item>
    <shape android:shape="rectangle" >
        <solid android:color="#FFF" />
    </shape>
</item>

<item android:bottom="-4dp" android:right="-4dp" android:left="1dp"
    android:top="-4dp">
    <shape>
        <solid android:color="@android:color/transparent" />
        <stroke
            android:dashGap="0px"
            android:dashWidth="0px"
            android:width="2dp"
            android:color="#EF5350" />
    </shape>
</item>

Then apply this margin to the linear layout as background

<LinearLayout
            android:layout_width="5dp"
            android:layout_height="100dp"
            android:id="@+id/tactic_linear_layout"
            android:background="@drawable/margin_color"
            android:orientation="horizontal"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="0dp"
            android:paddingBottom="0dp">

This method works for me try this....

Vertical line using XML drawable, Oh, I actually figured out a fix. Put it as background of view with fill_parent or fixed sized in dp height its very simple to add a vertical line in android xml. This example will create a 1dp thin black line on the right side of the view, that will  Vertical line using XML drawable (10) Depends, where you want to have the vertical line, but if you want a vertical border for example, you can have the parent view have a background a custom drawable. import matplotlib. ConstraintLayout is a layout on Android that gives you adaptable and flexible ways to create views for your apps.


Since you haven't given any code, you can draw a straight line like this :

                 <View
                    android:layout_width="1dp"
                    android:layout_height="50dp" 
                    android:background="#cdcdcd" />

How to draw Horizontal and Vertical lines in an Android App using , Consider the following XML code to draw a Vertical line in Android: In the above code, a red vertical line of height '560dp' and width '2dp' is drawn which is at  In this article i will show you how to create rectangle shape using xml in Android Application. It is an alternative method for graphics used for gradient


use below code in your xml file to draw fixed height line,

<View
    android:id="@+id/view_vertical_line"
    android:layout_width="1sp"
    android:layout_height="500sp"
    android:layout_marginLeft="15sp"
    android:background="@color/black" />

Linear Layout, You can specify the layout direction with the LinearLayout are stacked one after the other, so a vertical list will only have one child per row, no… To create a linear layout in which each child uses the same amount of The To field, Subject line, and Send button each take up only the height they need. I am trying to make a nice set of items, which are equally spaced from each other. On example below, I set buttons between empty textview. Every button and text view has height = 0dip and weight=1


you can draw vertical line having fixed height using the code below

   <View
        android:layout_width="specify thickness in dp"
        android:layout_height="specify fixed height in dp"
        android:background="specify color of line"/>

LinearLayout, The value you set affects both horizontal and vertical alignment of all a child view to affect its position and size in the containing linear layout. Icon Bar Menu Icon Accordion Tabs Vertical Tabs Tab Headers Full Page Tabs Hover Tabs Top Navigation Responsive Topnav Navbar with Icons Search Menu Search Bar Fixed Sidebar Side Navigation Responsive Sidebar Fullscreen Navigation Off-Canvas Menu Hover Sidenav Buttons Sidebar with Icons Horizontal Scroll Menu Vertical Menu Bottom Navigation Responsive Bottom Nav Bottom Border Nav Links Right Aligned Menu Links Centered Menu Link Equal Width Menu Links Fixed Menu Slide Down Bar on Scroll Hide


you can draw line using drawable also like this.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <stroke android:width="1dp" 
     android:color="@color/red"/>
    <size android:width="2dp" 
     android:height="290dp" />
</shape>

Guideline, Vertical Guidelines have a width of zero and the height of their to set a Guideline in XML, as well as the corresponding ConstraintSet. So making a Button or a TextView expand to fill a percent of the screen can be done with a few lines of XML. For example, if you want to set the width of the button to 70% of screen, you can do it like this: <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_constraintWidth_percent="0.7" />


How To Create a Vertical Line, Example. <style> .vl { border-left: 6px solid green; height: 500px; } </style> <div class="vl"></div>. Try it Yourself ». How to center the vertical line in your page:  To create a linear layout in which each child uses the same amount of space on the screen, set the android:layout_height of each view to "0dp" (for a vertical layout) or the android:layout_width of each view to "0dp" (for a horizontal layout). Then set the android:layout_weight of each view to "1". Unequal distribution


How to implement Vertical dotted line below image in Android , LINE SDK for Android You can build complex Flex Messages layouts based on the specification for CSS Flexible Box (CSS Flexbox) . This page explains how to adjust the overall layout, as well as the size and alignment of components (​child Alignment in the vertical direction is fixed at the baseline of the text. How to use assign width and height in % format in android linearlayout,RelativeLayout. Percentage format is used to mostly create web applications because websites are open in different types of screen sizes like CRT, LED, LCD, Tablets, Mobile phones etc.


Flex Message layout, vLine { border-left: 6px solid rgb(128, 0, 128); height: 500px; margin-left: 5%; } </​style> </head> <body> <h1>Vertical Line Example<h1> <div  The first method is to take a horizontal line and use the transform property to rotate it. For a vertical line you would rotate it 90 degrees.