Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Drawing Separator/Divider Line in Layout?

I would like to draw a line right in the middle of a layout and use it as a separator of other items like TextView. Is there a good widget for this. I don't really want to use an image as it would be hard to match the other components to it. And I want it to be relatively positioned as well. Thanks

like image 275
Androider Avatar asked Feb 19 '11 08:02

Androider


People also ask

How do you draw a line on Android screen?

quadTo(mX, mY, (x + mX)/2, (y + mY)/2); You will be able to draw straight lines.

What is the vertical line in Android Studio?

That line historically represents the margin of A4 paper, which is useful only if you need to print the code. Old school says that you should keep your code inside that margin, to guarantee much portability.


2 Answers

I usually use this code to add horizontal line:

<View     android:layout_width="match_parent"     android:layout_height="1dp"     android:background="@android:color/darker_gray"/> 

To add vertical separator, switch the layout_width and layout_height values

like image 122
Alex Kucherenko Avatar answered Oct 05 '22 11:10

Alex Kucherenko


To improve on the answers provided by Alex Kucherenko and Dan Dar3

I added this to my styles:

<style name="Divider">     <item name="android:layout_width">match_parent</item>     <item name="android:layout_height">1dp</item>     <item name="android:background">?android:attr/listDivider</item> </style> 

Then in my layouts is less code and simpler to read.

<View style="@style/Divider"/> 
like image 28
toddles_fp Avatar answered Oct 05 '22 11:10

toddles_fp