How to add cardview in layout xml in AndroidX

后端 未结 9 1139
臣服心动
臣服心动 2020-12-01 01:32

How to add cardview in layout xml in AndroidX

After upgraded to AndroidX



        
9条回答
  •  死守一世寂寞
    2020-12-01 02:10

    You have 2 different options:

    • Material Components MaterialCardView

    Just add:

    implementation 'com.google.android.material:material:1.2.0'
    

    and in your xml you can use:

     
    
    • Androidx CardView

    Just add:

    implementation 'androidx.cardview:cardview:1.0.0'
    

    and in your xml you can use:

    
    

    They are different:

    MaterialCardView extends androidx.cardview.widget.CardView and provides all of the features of CardView and

    • add support for checking and dragging
    • uses a MaterialComponents theme by default (it uses by deafult the style Widget.MaterialComponents.CardView)
    • support the ShapeAppearanceModel
    • adds attributes for customizing the stroke

提交回复
热议问题