简体   繁体   中英

How to disable the ripple effect?

I have a layout ConstraintLayout which has multiple children, and one child is having the ripple effect

(android:foreground="attr/selectableItemBackground")

and my parent ConstraintLayout also have the same ripple effect. My question is how to disable the child item ripple effect if the parent is already having the ripple, or any conditional way we can use to disable ripple.

when I click on parent item it shows both ripple parent as well as children.

 <android.support.constraint.ConstraintLayout
    android:id="@+id/investment_pack_item_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/selectableItemBackground"
    android:onClick="@{(v) -> handlers.onClick(v, obj)}">

    <android.support.v7.widget.AppCompatImageView
        android:id="@+id/logo_iv"
        android:layout_width="@dimen/margin_70dp"
        android:layout_height="@dimen/margin_70dp"
        android:layout_marginStart="@dimen/padding_layout"
        android:layout_marginLeft="@dimen/padding_layout"
        android:layout_marginTop="@dimen/padding_layout"
        app:imgUrl="@{obj.imageUrl}"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:placeHolder="@{@drawable/bg_grey_rectangle_rounded_corner}"
        app:shapeType="@{2}"
        tools:src="@tools:sample/avatars" />

    <include
        android:id="@+id/ivp_item_category"
        layout="@layout/ivp_item_category_returns_recycler_item"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintLeft_toRightOf="@+id/logo_iv"
        app:layout_constraintRight_toRightOf="parent"
        app:obj="@{obj}"
        app:type="@{Constants.OTHER_PACKS}" />

    <android.support.constraint.Barrier
        android:id="@+id/barrier_ivp_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:barrierDirection="bottom"
        app:constraint_referenced_ids="ivp_item_category,logo_iv" />

    <android.support.v7.widget.AppCompatImageView
        android:id="@+id/logo_icon"
        android:layout_width="@dimen/icon_height_width_xxsmall"
        android:layout_height="@dimen/icon_height_width_xxsmall"
        android:src="@mipmap/ic_launcher"
        app:imgUrl="@{obj.createdBy.imageUrl}"
        app:layout_constraintBottom_toBottomOf="@+id/created_by"
        app:layout_constraintLeft_toLeftOf="@+id/logo_iv"
        app:layout_constraintTop_toTopOf="@+id/created_by"
        app:placeHolder="@{@drawable/bg_grey_rectangle_rounded_corner}"
        app:shapeType="@{2}"
        tools:src="@tools:sample/avatars" />

    <android.support.v7.widget.AppCompatTextView
        android:id="@+id/created_by"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/padding_layout_8dp"
        android:layout_marginLeft="@dimen/padding_layout_8dp"
        android:layout_marginTop="@dimen/margin_4dp"
        android:layout_marginBottom="@dimen/padding_layout"
        android:text="@{obj.createdBy.name}"
        android:textColor="@color/text_color_dark_grey"
        android:textSize="@dimen/text_size_very_small"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0"
        app:layout_constraintLeft_toRightOf="@+id/logo_icon"
        app:layout_constraintRight_toLeftOf="@+id/risk_image"
        app:layout_constraintTop_toBottomOf="@+id/barrier_ivp_1"
        tools:text="Aditya Birla Mutual Fund" />

    <android.support.v7.widget.AppCompatImageView
        android:id="@+id/risk_image"
        android:layout_width="@dimen/margin_16dp"
        android:layout_height="@dimen/margin_16dp"
        android:layout_marginRight="@dimen/padding_layout_8dp"
        app:imgSrc="@{RiskView.getRiskImage(obj.riskType.id)}"
        app:layout_constraintBottom_toBottomOf="@+id/risk_type"
        app:layout_constraintEnd_toStartOf="@+id/risk_type"
        app:layout_constraintTop_toTopOf="@+id/risk_type"
        app:placeHolder="@{@drawable/bg_grey_rectangle_rounded_corner}"
        tools:src="@drawable/ic_transaction" />

    <android.support.v7.widget.AppCompatTextView
        android:id="@+id/risk_type"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/padding_layout_8dp"
        android:layout_marginRight="@dimen/padding_layout"
        android:includeFontPadding="false"
        android:text="@{obj.riskType.displayName}"
        android:textColor="@color/text_color_dark_grey"
        android:textSize="@dimen/text_size_very_small"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@+id/logo_icon"
        tools:text="Moderate" />

</android.support.constraint.ConstraintLayout>

Include layout

<android.support.constraint.ConstraintLayout
    android:id="@+id/lyt_category_returns_item"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clickable="@{!type.equals(Constants.OTHER_PACKS)}"
    android:foreground="?attr/selectableItemBackground"
    android:onClick="@{(v) -> handlers.onClick(v, obj)}"
    android:padding="@dimen/padding_layout">

    <TextView
        android:id="@+id/scheme_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:drawableEnd="@drawable/ic_forward"
        android:drawableRight="@drawable/ic_forward"
        android:drawablePadding="@dimen/margin_6dp"
        android:text="@{obj.fundName}"
        android:textColor="@color/text_color_black"
        android:textSize="@dimen/text_size_small"
        tools:text="Aditya Birla Mutual Fund" />

    <TextView
        android:id="@+id/fund_category_2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/padding_4dp"
        android:background="@drawable/rounded_corner_light_grey_bg"
        android:clickable="false"
        android:gravity="center"
        android:paddingLeft="@dimen/padding_layout_8dp"
        android:paddingTop="@dimen/padding_4dp"
        android:paddingRight="@dimen/padding_layout_8dp"
        android:paddingBottom="@dimen/padding_4dp"
        android:text="@{obj.fundCategory}"
        android:textColor="@color/text_color_dark_grey"
        android:textSize="@dimen/text_size_xs_small"
        android:visibility="@{obj.fundCategory != null ? View.VISIBLE : View.GONE}"
        app:layout_constraintTop_toBottomOf="@+id/scheme_name"
        tools:visibility="gone" />

    <android.support.v7.widget.AppCompatTextView
        android:id="@+id/minimum_investment_header"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/padding_layout_8dp"
        android:text="@string/minimum_investment"
        android:textColor="@color/text_color_grey"
        android:textSize="@dimen/text_size_very_small"
        app:layout_constraintEnd_toStartOf="@+id/category_returns_header"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintHorizontal_chainStyle="spread_inside"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/fund_category_2" />

    <TextView
        android:id="@+id/minimum_investment_value"
        style="@style/currencyTextStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/padding_layout_4dp"
        android:text="@{Apputility.getFormattedPrice(obj.minimumInvestment.doubleValue(), true, 0)}"
        android:textColor="@color/text_color_black"
        android:textSize="@dimen/text_size_small"
        app:layout_constraintLeft_toLeftOf="@+id/minimum_investment_header"
        app:layout_constraintTop_toBottomOf="@+id/minimum_investment_header"
        tools:text="₹ 1000" />

    <android.support.v7.widget.AppCompatTextView
        android:id="@+id/category_returns_header"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@{type.equals(Constants.OTHER_PACKS)?@string/schemes:@string/allocation}"
        android:textColor="@color/text_color_grey"
        android:textSize="@dimen/text_size_very_small"
        app:layout_constraintEnd_toStartOf="@+id/returns_header"
        app:layout_constraintStart_toEndOf="@+id/minimum_investment_header"
        app:layout_constraintTop_toTopOf="@+id/minimum_investment_header"
        tools:text="@string/schemes" />

    <android.support.v7.widget.AppCompatTextView
        android:id="@+id/allocation_percentage"
        style="@style/currencyTextStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/padding_4dp"
        android:text="@{type.equals(Constants.OTHER_PACKS)?``+obj.schemeCount:``}"
        android:textColor="@color/text_color_black"
        android:textSize="@dimen/text_size_small"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="@+id/category_returns_header"
        app:layout_constraintTop_toBottomOf="@+id/category_returns_header"
        tools:text="60"
        tools:visibility="visible" />

    <com.ui.common.CategoryReturnProgressView
        android:id="@+id/category_return_range"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginLeft="@dimen/padding_2dp"
        android:layout_marginEnd="@dimen/margin_30dp"
        android:layout_marginRight="@dimen/margin_30dp"
        app:categoryReturn="@{obj.allocation}"
        app:layout_constraintBottom_toBottomOf="@+id/allocation_percentage"
        app:layout_constraintLeft_toRightOf="@+id/allocation_percentage"
        app:layout_constraintRight_toLeftOf="@+id/returns_header"
        app:layout_constraintTop_toTopOf="@+id/allocation_percentage"
        app:min="@{obj.allocation}"
        app:visibility="@{!type.equals(Constants.OTHER_PACKS)}"
        tools:visibility="gone" />

    <android.support.v7.widget.AppCompatTextView
        android:id="@+id/returns_header"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@{(obj.bucket != null)?obj.bucket:@string/returns}"
        android:textColor="@color/text_color_grey"
        android:textSize="@dimen/text_size_very_small"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/category_returns_header"
        app:layout_constraintTop_toTopOf="@+id/minimum_investment_header"
        tools:text="Returns"
        tools:visibility="visible" />

    <TextView
        android:id="@+id/returns_value"
        style="@style/currencyTextStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/padding_layout_4dp"
        android:maxLines="1"
        android:minEms="3"
        android:textSize="@dimen/text_size_small"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/returns_header"
        app:return="@{obj.returns}"
        app:returnColor="@{obj.returns}"
        tools:text="+36.23%" />

</android.support.constraint.ConstraintLayout>

You can use custom style with a transparent color:

<style name="noRipple" parent="Theme.MaterialComponents">
    <item name="rippleColor">@android:color/transparent</item>
</style>

and set in your view:

style="@style/noRipple"

Hope it helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM