CardView圆角半径 [英] CardView Corner Radius

查看:582
本文介绍了CardView圆角半径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法,使CardView只有拐角半径在顶部?

 < android.support.v7.widget.CardView
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    应用程序:cardCornerRadius =10dp
    >
 

解决方案

除非你试图扩展的Andr​​oid CardView 类,不能自定义从<$ C $该属性C> XML 。

尽管如此,有获得这种效果的一种方式。

CardView 在另一个 CardView 并应用透明背景到您的外 CardView 并删除其圆角半径(cornerRadios = 0dp)。你内心的 CardView 将有3DP一个cornerRadius值,例如。然后,marginTop适用于你的内心 CardView ,所以其底部边界将由外切 CardView 。这样一来,你内心的底部圆角半径 CardView 将被隐藏。

中的XML code是如下:

 &LT; android.support.v7.widget.CardView
    的xmlns:card_view =htt​​p://schemas.android.com/apk/res-auto
    机器人:ID =@ + ID / card_view_outer
    机器人:layout_width =match_parent
    机器人:layout_height =200dp
    机器人:layout_gravity =中心
    card_view:cardBackgroundColor =@机器人:彩色/透明
    card_view:cardCornerRadius =0dp
    card_view:cardElevation =3DP&GT;

    &LT; android.support.v7.widget.CardView
        的xmlns:card_view =htt​​p://schemas.android.com/apk/res-auto
        机器人:ID =@ + ID / card_view_inner
        机器人:layout_width =match_parent
        机器人:layout_height =200dp
        机器人:layout_gravity =中心
        机器人:layout_marginTop =3DP
        card_view:cardBackgroundColor =@色/绿
        card_view:cardCornerRadius =4DP
        card_view:cardElevation =0dp&GT;
    &LT; /android.support.v7.widget.CardView>
&LT; /android.support.v7.widget.CardView>
 

和视觉效果如下:

始终把你的内容在内蒙古 CardView 。你的外CardView服务藏内 CardView

底部圆角的唯一目的

Is there a way to make CardView only have corner radius at the top?

<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:cardCornerRadius="10dp"
    >

解决方案

Unless you try to extend the Android CardView class, you cannot customize that attribute from XML.

Nonetheless, there is a way of obtaining that effect.

Place a CardView inside another CardView and apply a transparent background to your outer CardView and remove its corner radius ("cornerRadios = 0dp"). Your inner CardView will have a cornerRadius value of 3dp, for example. Then apply a marginTop to your inner CardView, so its bottom bounds will be cut by the outer CardView. This way, the bottom corner radius of your inner CardView will be hidden.

The XML code is the following:

 <android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/card_view_outer"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:layout_gravity="center"
    card_view:cardBackgroundColor="@android:color/transparent"
    card_view:cardCornerRadius="0dp"
    card_view:cardElevation="3dp" >

    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view_inner"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_gravity="center"
        android:layout_marginTop="3dp"
        card_view:cardBackgroundColor="@color/green"
        card_view:cardCornerRadius="4dp"
        card_view:cardElevation="0dp" >
    </android.support.v7.widget.CardView>
</android.support.v7.widget.CardView>

And the visual effect is the following:

Always put your content in your Inner CardView. Your outer CardView serves only the purpose of "hiding" the bottom Rounded Corners of the inner CardView.

这篇关于CardView圆角半径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆