2

I have solved a weird issue, and I would like to know why it happens.

My application creates screens with FrameLayout as the root element. For Simplicity, let´s say I have a Framelayout with some scrolling elements inside, for example a ScrollView with a TextView, and a GridView.

These child elements are positioned with LayoutParams so I assign them a Width, a Height, and a Margin Left / Margin Top. The usual case is their sizes do NOT match the parent, that is, they are floating inside the parent FrameLayout.

For non-scrolling elements, everything is cool.

But for scrolling elements, when scrolling, I can see all kinds of leftovers OUTSIDE the child bounds. Inside the bounds the scrolling is perfect, but the elements are not clipped properly.

I did a lot of tests, played with setClipChildren / setClipToBounds, changed the root element from FrameLayout to RelativeLayout, etc etc, without success.

I only succeeded when I wrapped the scrolling elements inside another Framelayout/RelativeLayout without any margins, and then assigned the scrolling elements MATCH_PARENT/MATCH PARENT.

The scroll is perfect now, clipping is properly done, but I have added another level of complexity to the layout.

Why does this happen?

4

0 回答 0