CardView with different corner radius

前端 未结 4 1031
小鲜肉
小鲜肉 2020-12-30 00:13

I have the following CardView and I want to set different radius for each corner in the card. Is it possible to change them by XML or programmaticaly? Thanks in advance.

4条回答
  •  再見小時候
    2020-12-30 01:06

    Hi you can add it programmatically or by xml with following code.

    app:cardCornerRadius="0dp"// xml
    cardView.setRadius(0);
    

    this one is extra who is looking for elevation

    app:cardElevation="0.7dp"//xml
    app:cardMaxElevation="1dp"//xml
    cardView.setCardElevation(2.1f);//code
    cardView.setMaxCardElevation(3f);//code
    

    The complete Java representation of the CardView’s XML.

    CardView cardView = (CardView) findViewById(R.id.cardView);
    cardView.setUseCompatPadding(true);
    cardView.setContentPadding(30, 30, 30, 0);
    cardView.setPreventCornerOverlap(true);
    cardView.setCardBackgroundColor(Color.WHITE);
    cardView.setCardElevation(2.1f);
    cardView.setRadius(0);
    cardView.setMaxCardElevation(3f);
    

提交回复
热议问题