selectableItemBackgroundBorderless が効かない場合の対処法
概要
Viewのサイズをはみ出した ripple エフェクトを適用したい時に便利な selectableItemBackgroundBorderless
は、特に親のViewGroupが ConstraintLayout
である場合に ripple が出ないといった意図しない挙動をすることがあります。
根本的な解決策を見つけるまでに時間がかかったので、自分用に調査したメモをまとめておきます。
結論
selectableItemBackgroundBorderless
が効かない場合は、selectableItemBackgroundBorderless
を適用しているViewを android:background="@android:color/transparent"
を設定したFrameLayout
でラップする。
なぜそうなるのか
StackOverflowの回答に的確な説明があったので、重要な部分の抄訳をしておきます。
Explanation:
"Borderless buttons draw their content on the closest background. Your button might not be having background between itself and the ImageView, so it draws underneath the ImageView."ボーダーレスボタンのコンテンツは最も近いbackgroundに描画されます。ボタンとそのそばにある
ImageView
の間にはbackgroundが存在しておらず、結果としてImageView
の下に描画されます。
参考
Author And Source
この問題について(selectableItemBackgroundBorderless が効かない場合の対処法), 我々は、より多くの情報をここで見つけました https://qiita.com/maxfie1d/items/7c2a436c2636927059e6著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .