Home > Software design >  i cant click whole cardview
i cant click whole cardview

Time:10-16

Hello i have a problem with my cardview. when i click whole cardview with binding.root.setonclicklistener{} doesnt work. only work when i click a little part on bottom. but also when i try click imageview (in my cardview) for favorite it works correctly. how can i fix that ?

<androidx.cardview.widget.CardView
        android:id="@ id/cv_product_item_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardCornerRadius="@dimen/radius_10dp"
        app:cardElevation="0dp">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@ id/cl_product_item_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/bg_bordered_ghost_white_with_radius_10dp_width_1dp">

            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@ id/cl_product_item_top_container"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                app:layout_constraintBottom_toTopOf="@ id/cl_product_item_bottom_container"
                app:layout_constraintDimensionRatio="0.78"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent">

                <androidx.viewpager2.widget.ViewPager2
                    android:id="@ id/vp_product_item_images"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@color/silver"
                    android:elevation="-1dp"
                    android:orientation="horizontal" />

                <com.google.android.material.tabs.TabLayout
                    android:id="@ id/tl_product_item"
                    android:layout_width="wrap_content"
                    android:layout_height="@dimen/size_25"
                    android:background="@color/white_p0"
                    app:tabBackground="@drawable/selector_indicator_white_4dp"
                    app:tabGravity="center"
                    app:tabIndicatorHeight="0dp"
                    app:tabPaddingEnd="@dimen/size_15"
                    app:tabPaddingStart="@dimen/size_15"
                    app:tabPaddingTop="0dp"
                    android:layout_marginBottom="@dimen/margin_25"
                    android:layout_marginStart="@dimen/margin_50"
                    app:layout_constraintBottom_toTopOf="@id/cv_product_item_top"
                    app:layout_constraintStart_toStartOf="@id/vp_product_item_images"/>

                <androidx.appcompat.widget.AppCompatImageView
                    android:id="@ id/iv_product_item_favorite"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="@dimen/padding_50"
                    android:src="@{data.isFavorite ? @drawable/ic_favorite_filled_cerise : @drawable/ic_favorite_empty_lilac_bloom}"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    tools:src="@drawable/ic_favorite_filled_cerise" />

CodePudding user response:

Try this -

Add these 2 attributes in your card view - android:clickable="true" and android:focusable="true"

CodePudding user response:

when i change viewpager height for example 20dp i noticed click is works except the 20dp. viewpager doesnt allow me for click. i tried clickable and focusable false in viewpager but still same :(

<androidx.cardview.widget.CardView
        android:id="@ id/cv_product_item_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardCornerRadius="@dimen/radius_10dp"
        app:cardElevation="0dp">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@ id/cl_product_item_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/bg_bordered_ghost_white_with_radius_10dp_width_1dp">

            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@ id/cl_product_item_top_container"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                app:layout_constraintBottom_toTopOf="@ id/cl_product_item_bottom_container"
                app:layout_constraintDimensionRatio="0.78"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent">

                <androidx.viewpager2.widget.ViewPager2
                    android:id="@ id/vp_product_item_images"
                    android:layout_width="match_parent"
                    android:layout_height="20dp"
                    android:background="@color/silver"
                    android:elevation="-1dp"
                    android:orientation="horizontal" />
  • Related