sswierczek sswierczek - 3 months ago 39
Android Question

Add padding to FrameLayout programmatically without moving inner Fragment with ScrollView content

I need to add bottom padding or margin to the

FrameLayout
in an
Activity
programmatically after some delay. Problem is that it is container for
Fragments
with
ScrollView
. When I set bottom padding/margin to it inner content is scrolled upwards. Top part of
Fragment
content is not visible anymore.

It works well when I set bottom padding to
ScrollView
content but I want to avoid that and handle it in an
Activity
without need to modify every single
Fragment
.

I tried:


  • set bottom margin/padding to
    FrameLayout

  • put
    View
    at the bottom of
    FrameLayout
    in
    LinearLayout
    ,

  • set
    android:clipToPadding="false"
    to
    ScrollView
    .



The same behaviour every time. Any ideas?

Answer

I figure out it by myself. It seems that this is issue occurs whensetVerticalFadingEdgeEnabled(true)is used withsetFadingEdgeLength() onScrollView.

This hack solved the issue:

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    setVerticalFadingEdgeEnabled(false);
    super.onSizeChanged(w, h, oldw, oldh);
    setVerticalFadingEdgeEnabled(true);
}