0

I have a LinearLayout inside of a Scrollview. After doing some animations, there is blank space at the bottom when I scroll down. So I want to resize the LinearLayout using this code

                ViewGroup.LayoutParams params = _linearLayoutMainWrapper.getLayoutParams();
                params.height = 100;
                _linearLayoutMainWrapper.setLayoutParams(params);

It doesnt work though, just nothing is happening. When I try to resize the width it is working though.

The XML is

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:animateLayoutChanges="true"
    android:fillViewport="true"
    android:id="@+id/scrollViewMain">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:animateLayoutChanges="true"
        android:orientation="vertical"
        android:paddingLeft="16dip"
        android:paddingRight="16dip"
        android:id="@+id/linearLayoutMainWrapper">

        <!-- a lot of stuff -->

    </LinearLayout>

</ScrollView>
David Dunham
  • 8,139
  • 3
  • 28
  • 41
Luca Thiede
  • 3,229
  • 4
  • 21
  • 32
  • Can you show your "_linearLayoutMainWrapper" xml layout . sometimes the error lies in attributes , for instance in some cases , setting the height to wrap_content will prevent you from changing height later. – AmiNadimi Sep 23 '16 at 18:34
  • Why you not use android:layout_height="wrap_content" on your LinearLayout? Your layout always get height from scrollview. Maybe try edit height of scrollview or change linearlayout height property to wrap_content. – M. Wiśnicki Sep 23 '16 at 18:58
  • I did, it didnt work, so I changed it, because the comment above says that "wrap_content" can cause problems. It still doesnt work though. – Luca Thiede Sep 23 '16 at 19:00
  • give the layout height some constant value and check again . it might help out since the value won't be dependent on any other elements. – AmiNadimi Sep 24 '16 at 11:30

1 Answers1

0

Maybe you have some margin setted for this view ? Try to clear in params margins and the height for LinearLayout should be youScrollView.getMeasuredHeight().

kenzo
  • 211
  • 1
  • 9
  • Which view do you mean? The one I was performing animations on? It is one of many views, I hide by translating it upwards "under another view" Thanks for the tip with the .getMeasuredHeight() though – Luca Thiede Sep 23 '16 at 18:32
  • That 'view' maybe be either LinearLayout - margin or ScrollView - padding. What animations are you performing ? – kenzo Sep 23 '16 at 18:35