Android 如何在CardView中剪切垂直线?
我想在radius CardView中剪切垂直线视图 如图所示:Android 如何在CardView中剪切垂直线?,android,android-layout,android-cardview,Android,Android Layout,Android Cardview,我想在radius CardView中剪切垂直线视图 如图所示: 兄弟,试试这个 <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-a
兄弟,试试这个
<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>
您可以尝试为剪辑视图设置曲线形状的背景资源
这是一个示例形状文件,您需要根据需要修改半径值
<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>
以及主CardView布局:
<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>
您是否尝试了视图
中提到的宽度
和高度
@shashashanth您能帮我吗?@vimukthi是的。不工作。嗨,谢谢。我复制了你的代码,但是我得到了不同的结果!!请看:为什么?您使用了我给出的全部代码还是仅使用了视图?是的,我复制并粘贴了此内容。现在我在genymotion emulator上进行了尝试,在api 4和7上有不同的功能。看:这是真的。但只有在高api的android版本上才能工作。谢谢,我认为这是最好的办法。谢谢你,伙计,很高兴帮助你。
<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>