0

I have a card view with app:cardCornerRadius="20dp"

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="140dp"
        android:layout_margin="10dp"
        android:clickable="true"
        android:focusable="true"
        android:foreground="?attr/selectableItemBackgroundBorderless"
        app:cardCornerRadius="20dp">



    </android.support.v7.widget.CardView>

</LinearLayout>

Now I want add two vertical solid line to right of this. like this:

enter image description here

Also vertical line must be have radius.

EDIT:

I write this:

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="140dp"
    android:layout_margin="10dp"
    android:clickable="true"
    android:focusable="true"
    android:foreground="?attr/selectableItemBackgroundBorderless"
    app:cardCornerRadius="50dp">


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

        <View
            android:layout_width="5dp"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            android:layout_marginRight="10dp"
            android:background="@color/colorBlack" />


    </RelativeLayout>

</android.support.v7.widget.CardView>

And get this result:

enter image description here

I need radius for line

Zardchoobe
  • 37
  • 1
  • 6

3 Answers3

0

You can add as many as you want by adding view, like this :

 <View
    android:layout_width="2dp"
    android:layout_height="match_parent"
    android:layout_margin="@dimen/medium_margin"
    android:background="@color/darkGray" />
Zaid Mirza
  • 2,866
  • 1
  • 18
  • 35
  • I need also radius for it. similar to this pic: https://i.stack.imgur.com/hZQvh.png – Zardchoobe Dec 31 '18 at 14:14
  • it is radius for card, not for lines. – Zaid Mirza Dec 31 '18 at 14:20
  • No No, my card have radius. but not applied in lines. see my code in my updated question. – Zardchoobe Dec 31 '18 at 14:35
  • CardView on older APIs doesn't round its content's corners, so setting radius to the card won't help. – Zielony Dec 31 '18 at 14:37
  • @Zielony what's the solution ? except 9-patch – Zardchoobe Dec 31 '18 at 14:41
  • Backport content rounding from Lollipop, but that's not exactly the easiest thing in the world. It's also very computation heavy and not a good practice for just drawing lines. If you wish, here's a piece of code doing that using Carbon: https://gist.github.com/ZieIony/9121c6a0d1b4d7846260200d0ece25ea And the result: https://ibb.co/4VRyzHK – Zielony Dec 31 '18 at 14:57
0

You could use a View within your cardview xml, this will give you the vertical lines you require as xml.

see this post for ref: vertical line

GordonW
  • 1,020
  • 2
  • 16
  • 36
-1

You just need a 9-patch with two lines. That's it. Something like this:

enter image description here

If you target API 21+, then you don't even need to care about rounded corners. Background will be cut to CardView's outline anyway. If you target older Android versions, then you need to add these rounded corners to background drawable, but that doesn't change much.

Zielony
  • 14,767
  • 5
  • 29
  • 37
  • As I wrote, that doesn't change anything. 9-patch is the official way of doing such backgrounds and it worked fine since the first Android. For API 16 you need the full drawable with lines and corners. See: https://developer.android.com/studio/write/draw9patch – Zielony Dec 31 '18 at 14:35