Stacking image views with overlapping

前端 未结 2 1077
后悔当初
后悔当初 2021-01-17 01:56

I am trying to stack image views beside each other (with 70% overlapping). I used a frameLayout and gave each elemnet padding of 10. It worked but this padding is killing me

2条回答
  •  情歌与酒
    2021-01-17 02:19

    Create a custom ViewGroup that lays out it's children in onLayout. There are quite a few examples if you search for "custom ViewGroup onLayout". In general, the onLayout method override looks like this:

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {}
    

    Inside that method, you will want to use getChildCount() and getChildAt(index) to get references to your child views. Once you have them, you can use the l,t,r, and b values to compare the bounds of your ViewGroup and figure out where to layout the children.

    Once you find the children and calculate where you want them, you'll use child.layout(l,t,r,b) to place the child view inside your new custom ViewGroup.

    Hope this helps. if you REALLY need to hack this into XML, you can try the following :

     
             
     
     
    
    

提交回复
热议问题