How to layer views

后端 未结 3 600
萌比男神i
萌比男神i 2020-12-06 05:18

I have a custom-made view that extends the View class. I would like 2 instances of my custom view layered directly on top of each other. How should my layout file look to ac

3条回答
  •  隐瞒了意图╮
    2020-12-06 05:35

    While it's true that you can achieve layering using RelativeLayout and FrameLayout, in API 21 and higher.. things have changed.

    In API 21 and higher, the later children of xml doesn't mean it will overlap earlier children. Instead, it uses Elevation to determine which view will overlap other view (Z-Index).

    For example, if you have something like this.

    
    
        

    The View will not be visible even though it was added after Button. That's because Button has higher elevation than View. To rearrange Z-Index you can add elevation attribute to respective views.

    
    
        

    This way the View will overlap the Button.

    More Information on Elevation & Shadows: https://material.io/guidelines/material-design/elevation-shadows.html

提交回复
热议问题