问题
I want clipping vertical line view in radius CardView
like this pic:
<?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="20dp"
app:cardCornerRadius="40dp">
<!-- radiused vertical line here -->
</android.support.v7.widget.CardView>
</LinearLayout>
回答1:
You can try setting curved-shaped background resource for the clipping views.
Here is a sample shape file, you need to modify the radius values according to your need.
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#a40404" />
<corners
android:topRightRadius="40dp"
android:bottomRightRadius="40dp"/>
</shape>
And the main CardView layout:
<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="20dp"
app:cardCornerRadius="40dp"
app:cardPreventCornerOverlap="false">
<View
android:layout_width="5dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:background="@drawable/curved_bg" />
<View
android:layout_width="5dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:layout_marginTop="3dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="3dp"
android:background="@drawable/curved_bg" />
</android.support.v7.widget.CardView>
</LinearLayout>
回答2:
Bro try this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:gravity="center"
android:orientation="vertical"
android:padding="16dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="140dp"
android:layout_margin="20dp"
app:cardCornerRadius="40dp">
<View
android:layout_width="5dp"
android:layout_height="300dp"
android:layout_gravity="right"
android:layout_marginRight="10dp"
android:background="#a40404" />
<View
android:layout_width="5dp"
android:layout_height="300dp"
android:layout_gravity="right"
android:layout_marginRight="20dp"
android:background="#a40404" />
<!-- radiused vertical line here -->
</android.support.v7.widget.CardView>
</LinearLayout>
来源:https://stackoverflow.com/questions/53991918/how-i-can-clipping-vertical-line-in-a-cardview