I have this XML

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" android:thickness="0dp"> <stroke android:width="2dp" android:color="@color/ntz_color_yellow" /> <corners android:radius="2dp" /> </shape> 

If I give it to my view as background, then I get an outline around my view. I need to add a vertical line to the XML in the middle. I know how to draw a horizontal line in XML

 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line"> <stroke android:width="1dp" android:color="#000000"> </stroke> </shape> 

But how to combine this into one XML? So that there was a contour and in the middle from edge to edge there was a vertical line? As a separator of sorts?

2 answers 2

On the advice of Chaynik'a use a layer-list. In it, the second element is a horizontal line rotated by 90 degrees.

 <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" android:thickness="0dp" android:color="@color/yellow"> <stroke android:width="2dp" android:color="@color/green" /> <corners android:radius="2dp" /> </shape> </item> <item> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="90" android:toDegrees="90"> <shape android:shape="line"> <stroke android:width="2dp" android:color="@color/red" /> </shape> </rotate> </item> </layer-list> 

Helped the answer from here.

  • Thank! Everything works, and now it became clear how to work with the layer-list - Aleksey Timoshchenko
  • @AlekseyTimoshchenko Not at all. For me, the answer to this question was also instructive))) - iramm

Use LinearLayout with a horizontal orientation in which you place two display areas of something.

https://developer.android.com/reference/android/widget/LinearLayout.html http://developer.alexanderklimov.ru/android/layout/linearlayout.php https://stackoverflow.com/questions/2961777/android- linearlayout-horizontal-with-wrapping-children

  • No, this option does not quite fit as I already have one item in the container, and if I start adding more, I’ll understand that at least the separators will not be in the middle ... I understand that it’s necessary to draw a line in XML .. If you have an idea how to solve it? - Aleksey Timoshchenko