LoginSignup
0
1

More than 1 year has passed since last update.

selectableItemBackgroundBorderless が効かない場合の対処法

Last updated at Posted at 2021-09-28

概要

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 の下に描画されます。

参考

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1