Android: Draw vertical line in a layout












-1















I am trying to draw vertical line in a row layout of the list (Recycler View). The line should be align left of the layout with margin left 20dp and the line height should be auto, when the content of the row layout increasse the vertical line align that align left of the layout also should increase.



I tried to add line by drawing the vertical line in drawable folder and add it to the background of the layout. But the problem is line comes only as the half



Draw able : vertical_line.xml



<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="90"
android:toDegrees="90"
android:pivotX="10">
<shape
android:shape="line">
<stroke
android:width="1dp"
android:color="#ff00ff"
/>
</shape>




Layout



<?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="wrap_content"
android:background="@color/black_two">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:background="@drawable/vertical_line"
>
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="text"
android:textColor="@color/white"/>
</RelativeLayout>




Please help me to draw a line on the left of the layout with auto height










share|improve this question

























  • Do you really a drawable xml to draw a vertical line? Because you can also do that with just views...

    – Aaron
    Nov 22 '18 at 4:11











  • Your parent RelativeLayout height is "wrap_content " change it to "match_parent" so that it will draw a line on the whole screen

    – Akshay Katariya
    Nov 22 '18 at 4:12











  • @ Aaron if we use <View> how to make that height as wrap_content

    – Binil Surendran
    Nov 22 '18 at 4:16











  • @Akshay Katariya am using this layout as the row item of my list, so how can i change row parent layout to match_parent?. if so 1 Row consume full height of the view.

    – Binil Surendran
    Nov 22 '18 at 4:17











  • @BinilSurendran If you use <View>, just set the height to match_parent.

    – Aaron
    Nov 22 '18 at 4:18
















-1















I am trying to draw vertical line in a row layout of the list (Recycler View). The line should be align left of the layout with margin left 20dp and the line height should be auto, when the content of the row layout increasse the vertical line align that align left of the layout also should increase.



I tried to add line by drawing the vertical line in drawable folder and add it to the background of the layout. But the problem is line comes only as the half



Draw able : vertical_line.xml



<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="90"
android:toDegrees="90"
android:pivotX="10">
<shape
android:shape="line">
<stroke
android:width="1dp"
android:color="#ff00ff"
/>
</shape>




Layout



<?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="wrap_content"
android:background="@color/black_two">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:background="@drawable/vertical_line"
>
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="text"
android:textColor="@color/white"/>
</RelativeLayout>




Please help me to draw a line on the left of the layout with auto height










share|improve this question

























  • Do you really a drawable xml to draw a vertical line? Because you can also do that with just views...

    – Aaron
    Nov 22 '18 at 4:11











  • Your parent RelativeLayout height is "wrap_content " change it to "match_parent" so that it will draw a line on the whole screen

    – Akshay Katariya
    Nov 22 '18 at 4:12











  • @ Aaron if we use <View> how to make that height as wrap_content

    – Binil Surendran
    Nov 22 '18 at 4:16











  • @Akshay Katariya am using this layout as the row item of my list, so how can i change row parent layout to match_parent?. if so 1 Row consume full height of the view.

    – Binil Surendran
    Nov 22 '18 at 4:17











  • @BinilSurendran If you use <View>, just set the height to match_parent.

    – Aaron
    Nov 22 '18 at 4:18














-1












-1








-1


0






I am trying to draw vertical line in a row layout of the list (Recycler View). The line should be align left of the layout with margin left 20dp and the line height should be auto, when the content of the row layout increasse the vertical line align that align left of the layout also should increase.



I tried to add line by drawing the vertical line in drawable folder and add it to the background of the layout. But the problem is line comes only as the half



Draw able : vertical_line.xml



<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="90"
android:toDegrees="90"
android:pivotX="10">
<shape
android:shape="line">
<stroke
android:width="1dp"
android:color="#ff00ff"
/>
</shape>




Layout



<?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="wrap_content"
android:background="@color/black_two">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:background="@drawable/vertical_line"
>
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="text"
android:textColor="@color/white"/>
</RelativeLayout>




Please help me to draw a line on the left of the layout with auto height










share|improve this question
















I am trying to draw vertical line in a row layout of the list (Recycler View). The line should be align left of the layout with margin left 20dp and the line height should be auto, when the content of the row layout increasse the vertical line align that align left of the layout also should increase.



I tried to add line by drawing the vertical line in drawable folder and add it to the background of the layout. But the problem is line comes only as the half



Draw able : vertical_line.xml



<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="90"
android:toDegrees="90"
android:pivotX="10">
<shape
android:shape="line">
<stroke
android:width="1dp"
android:color="#ff00ff"
/>
</shape>




Layout



<?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="wrap_content"
android:background="@color/black_two">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:background="@drawable/vertical_line"
>
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="text"
android:textColor="@color/white"/>
</RelativeLayout>




Please help me to draw a line on the left of the layout with auto height







android android-layout






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 30 '18 at 8:57









Onik

11.2k103863




11.2k103863










asked Nov 22 '18 at 4:07









Binil SurendranBinil Surendran

78121642




78121642













  • Do you really a drawable xml to draw a vertical line? Because you can also do that with just views...

    – Aaron
    Nov 22 '18 at 4:11











  • Your parent RelativeLayout height is "wrap_content " change it to "match_parent" so that it will draw a line on the whole screen

    – Akshay Katariya
    Nov 22 '18 at 4:12











  • @ Aaron if we use <View> how to make that height as wrap_content

    – Binil Surendran
    Nov 22 '18 at 4:16











  • @Akshay Katariya am using this layout as the row item of my list, so how can i change row parent layout to match_parent?. if so 1 Row consume full height of the view.

    – Binil Surendran
    Nov 22 '18 at 4:17











  • @BinilSurendran If you use <View>, just set the height to match_parent.

    – Aaron
    Nov 22 '18 at 4:18



















  • Do you really a drawable xml to draw a vertical line? Because you can also do that with just views...

    – Aaron
    Nov 22 '18 at 4:11











  • Your parent RelativeLayout height is "wrap_content " change it to "match_parent" so that it will draw a line on the whole screen

    – Akshay Katariya
    Nov 22 '18 at 4:12











  • @ Aaron if we use <View> how to make that height as wrap_content

    – Binil Surendran
    Nov 22 '18 at 4:16











  • @Akshay Katariya am using this layout as the row item of my list, so how can i change row parent layout to match_parent?. if so 1 Row consume full height of the view.

    – Binil Surendran
    Nov 22 '18 at 4:17











  • @BinilSurendran If you use <View>, just set the height to match_parent.

    – Aaron
    Nov 22 '18 at 4:18

















Do you really a drawable xml to draw a vertical line? Because you can also do that with just views...

– Aaron
Nov 22 '18 at 4:11





Do you really a drawable xml to draw a vertical line? Because you can also do that with just views...

– Aaron
Nov 22 '18 at 4:11













Your parent RelativeLayout height is "wrap_content " change it to "match_parent" so that it will draw a line on the whole screen

– Akshay Katariya
Nov 22 '18 at 4:12





Your parent RelativeLayout height is "wrap_content " change it to "match_parent" so that it will draw a line on the whole screen

– Akshay Katariya
Nov 22 '18 at 4:12













@ Aaron if we use <View> how to make that height as wrap_content

– Binil Surendran
Nov 22 '18 at 4:16





@ Aaron if we use <View> how to make that height as wrap_content

– Binil Surendran
Nov 22 '18 at 4:16













@Akshay Katariya am using this layout as the row item of my list, so how can i change row parent layout to match_parent?. if so 1 Row consume full height of the view.

– Binil Surendran
Nov 22 '18 at 4:17





@Akshay Katariya am using this layout as the row item of my list, so how can i change row parent layout to match_parent?. if so 1 Row consume full height of the view.

– Binil Surendran
Nov 22 '18 at 4:17













@BinilSurendran If you use <View>, just set the height to match_parent.

– Aaron
Nov 22 '18 at 4:18





@BinilSurendran If you use <View>, just set the height to match_parent.

– Aaron
Nov 22 '18 at 4:18












1 Answer
1






active

oldest

votes


















1














You can use View for vertical line instead of a shape:



<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:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:background="#ff00ff"/>

<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="text"
android:textColor="@color/white"/>
</LinearLayout>





share|improve this answer
























  • Thanks man, I was tried same thing with the parent layout as < Relative Layout>, but as you said after change it to <Linear Layout> it is success.

    – Binil Surendran
    Nov 22 '18 at 4:22











  • You're welcome. If you change the TextView height to wrap_content, it will still work - the View height will be adjusted to match its parent, which is affected by the TextView.

    – Aaron
    Nov 22 '18 at 4:26











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423745%2fandroid-draw-vertical-line-in-a-layout%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You can use View for vertical line instead of a shape:



<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:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:background="#ff00ff"/>

<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="text"
android:textColor="@color/white"/>
</LinearLayout>





share|improve this answer
























  • Thanks man, I was tried same thing with the parent layout as < Relative Layout>, but as you said after change it to <Linear Layout> it is success.

    – Binil Surendran
    Nov 22 '18 at 4:22











  • You're welcome. If you change the TextView height to wrap_content, it will still work - the View height will be adjusted to match its parent, which is affected by the TextView.

    – Aaron
    Nov 22 '18 at 4:26
















1














You can use View for vertical line instead of a shape:



<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:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:background="#ff00ff"/>

<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="text"
android:textColor="@color/white"/>
</LinearLayout>





share|improve this answer
























  • Thanks man, I was tried same thing with the parent layout as < Relative Layout>, but as you said after change it to <Linear Layout> it is success.

    – Binil Surendran
    Nov 22 '18 at 4:22











  • You're welcome. If you change the TextView height to wrap_content, it will still work - the View height will be adjusted to match its parent, which is affected by the TextView.

    – Aaron
    Nov 22 '18 at 4:26














1












1








1







You can use View for vertical line instead of a shape:



<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:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:background="#ff00ff"/>

<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="text"
android:textColor="@color/white"/>
</LinearLayout>





share|improve this answer













You can use View for vertical line instead of a shape:



<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:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:background="#ff00ff"/>

<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="text"
android:textColor="@color/white"/>
</LinearLayout>






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 '18 at 4:17









AaronAaron

1,7031212




1,7031212













  • Thanks man, I was tried same thing with the parent layout as < Relative Layout>, but as you said after change it to <Linear Layout> it is success.

    – Binil Surendran
    Nov 22 '18 at 4:22











  • You're welcome. If you change the TextView height to wrap_content, it will still work - the View height will be adjusted to match its parent, which is affected by the TextView.

    – Aaron
    Nov 22 '18 at 4:26



















  • Thanks man, I was tried same thing with the parent layout as < Relative Layout>, but as you said after change it to <Linear Layout> it is success.

    – Binil Surendran
    Nov 22 '18 at 4:22











  • You're welcome. If you change the TextView height to wrap_content, it will still work - the View height will be adjusted to match its parent, which is affected by the TextView.

    – Aaron
    Nov 22 '18 at 4:26

















Thanks man, I was tried same thing with the parent layout as < Relative Layout>, but as you said after change it to <Linear Layout> it is success.

– Binil Surendran
Nov 22 '18 at 4:22





Thanks man, I was tried same thing with the parent layout as < Relative Layout>, but as you said after change it to <Linear Layout> it is success.

– Binil Surendran
Nov 22 '18 at 4:22













You're welcome. If you change the TextView height to wrap_content, it will still work - the View height will be adjusted to match its parent, which is affected by the TextView.

– Aaron
Nov 22 '18 at 4:26





You're welcome. If you change the TextView height to wrap_content, it will still work - the View height will be adjusted to match its parent, which is affected by the TextView.

– Aaron
Nov 22 '18 at 4:26


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423745%2fandroid-draw-vertical-line-in-a-layout%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen