Extend CardView makes cardview's own attributes not functional at all

Viewed 31

I was trying to extend CardView on Android by kotlin using the following code:

HotCommentView.kt

class HotCommentView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : CardView(context, attrs) {

    private var binding: LayoutHotCommentBinding

    init {
        binding = LayoutHotCommentBinding.inflate(LayoutInflater.from(context), this, true)
    }

layout_hot_comment.xml

<androidx.cardview.widget.CardView 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="wrap_content"
    app:cardBackgroundColor="#f6f6f6"
    app:cardCornerRadius="5dp"
    app:cardElevation="0dp">

<!-- Some widgets -->

</androix.cardview.widget.CardView>

After that I tried to use my HotCommentView in other layout file, and I found out that cardElevation, cardCornerRadius did not function at all. The custom card view still have elevation and did not have 5dp of corner radius.

<com.xxx.view.HotCommentView
            android:id="@+id/hot_comment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="13dp" />

What am I doing wrong with extend cardview?

0 Answers
Related