Material ripple effect hidden by other view in layout

后端 未结 4 2076
一个人的身影
一个人的身影 2020-12-05 14:51

I added a ripple effect on a ImageButton, however it is hidden by an ImageView used as a background for the parent view RelativeLayout

4条回答
  •  感动是毒
    2020-12-05 15:37

    I'm aware this is an old post but I did struggle with this quite a bit today hence I'm posting what I was finally able to figure out and maybe someone else might benefit from it. One key emphasis beforehand, please do always RTFM!

    1) The story

    I aimed to use the unbounded ripple effect on Tab Items and consequently have it spread all over the AppBarLayout area. I had applied @android:color/transparent to TabLayout as the first wrapping parent and gave AppBarLayout a background color, nevertheless the ripple was still being cut off right at the borders of TabLayout's height.

    2) The moral of the story (RTFM)

    So I run to the nest of Android knowledge: The Documentation, and spotted this:

    ?android:attr/selectableItemBackgroundBorderless for a ripple that extends beyond the view. It will be drawn upon, and bounded by, the nearest parent of the view with a non-null background.

    3) The course of action

    Using Layout Inspector, I realized that @android:color/transparent although transparent (duh!) it actually assigns 0 as the value of the bg attribute of a View, but zero is not null hence the ripple gets bounded at the nearest parent.

    4) The conclusion

    With that in hand, I went and set the android:background property of my TabLayout to @null rather than transparent, and now I have a fancy little ripple spread onto the area of the AppBarLayout.

    5) Outro: **ANDROID & SO FTW!

    Props to everyone in this post who shed light on the matter in word. Cheers!

提交回复
热议问题