CardView 设置圆角方法

2025-10-25 20:06:04

1、添加依赖

implementation‘com.android.support:cardview-v7:23.4.0’

2、设置CardView的圆角半径


app:cardCornerRadius =""

设置背景颜色 

app:cardBackgroundColor=" 


设置padding

app:contentPadding=" "

app:contentPaddingTop=" "

app:contentPaddingBottom=" "

app:contentPaddingLeft=" "

app:contentPaddingRight=" 


注意啊:上面是CardView设置背景颜色和padding的方式,如果你直接通过android:padding=" " 和android:background=" "设置,是无效
设置Z轴的高度

app:cardMaxElevation=" "

设置CardView的前景


android:foreground =""


设置内边距
app:contentPadding ="

3、在项目中使用:

<LinearLayout 

 xmlns:android="http://schemas.android.com/apk/res/android"   

 xmlns:tools="http://schemas.android.com/tools"    

 xmlns:card_view="...">  

 <!-- A CardView that contains a TextView -->     

<android.support.v7.widget.CardView        

    xmlns:card_view="..."        

    android:id="@+id/card_view"        

    android:layout_gravity="center"        

    android:layout_width="200dp"        

    android:layout_height="200dp"        

    card_view:cardCornerRadius="4dp">  

      

 <TextView            

    android:id="@+id/info_text"           

    android:layout_width="match_parent"            

    android:layout_height="match_parent" />

    

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

</LinearLayout>

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢