title: android - Setting ScrollView height dynamically
body: <p>I have a layout wich is nested like this:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent" &gt;
  
      &lt;ScrollView 
          android:id="@+id/scrollAplicacoes"
          android:layout_width="match_parent"
          android:layout_height="wrap_content" &gt;
  
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="vertical"
              android:paddingBottom="@dimen/activity_vertical_margin"
              android:paddingLeft="@dimen/activity_horizontal_margin"
              android:paddingRight="@dimen/activity_horizontal_margin"
              android:paddingTop="@dimen/activity_vertical_margin" &gt;
  
              &lt;TextView 
                  android:id="@+id/titulo"
                  android:layout_width="match_parent"
                  android:layout_height="60dp"
                  android:fontFamily="Arial"
                  android:lineSpacingExtra="-5dp"
                  android:text="@string/titulo_aplicacao"
                  android:textColor="#3c3c3c"
                  android:textSize="25sp"
                  android:textStyle="bold"/&gt;
  
              &lt;ImageView
                  android:id="@+id/btnAplicacaoUm"
                  android:layout_width="match_parent"
                  android:layout_height="150dp"
                  android:onClick="selectAplicacao"
                  android:src="@drawable/aplicacoes_item1" /&gt;
  
              &lt;ImageView
                  android:id="@+id/btnAplicacaoDois"
                  android:layout_width="match_parent"
                  android:layout_height="150dp"
                  android:layout_marginTop="10dp"
                  android:onClick="selectAplicacao"
                  android:src="@drawable/aplicacoes_item2" /&gt;
  
              &lt;ImageView
                  android:id="@+id/btnAplicacaoTres"
                  android:layout_width="match_parent"
                  android:layout_height="150dp"
                  android:layout_marginTop="10dp"
                  android:onClick="selectAplicacao"
                  android:src="@drawable/aplicacoes_item3" /&gt;
  
          &lt;/LinearLayout&gt;
  
      &lt;/ScrollView&gt;
  
      &lt;LinearLayout 
          android:id="@+id/menuFixo"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true"
          android:background="@drawable/faixa_below" &gt;
  
          &lt;ImageView
              android:id="@+id/belowHome"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_weight="1"
              android:contentDescription="@string/descBtnHome"
              android:layout_marginTop="5dp"
              android:src="@drawable/below_home_sel" /&gt;
  
          &lt;ImageView
              android:id="@+id/belowCalculadora"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_weight="1"
              android:onClick="abreCalculadora"
              android:contentDescription="@string/descBtnCalculadora"
              android:layout_marginTop="5dp"
              android:src="@drawable/below_calc" /&gt;
  
          &lt;ImageView
              android:id="@+id/belowProdutos"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:contentDescription="@string/descFaixaProdutos"
              android:layout_marginTop="5dp"
              android:layout_weight="1"
              android:src="@drawable/below_produtos" /&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>The problem is that the LinearLayout outside the ScrollView, at the end is fixed on the bottom, and the scroll is placed behind it. So i need the Scroll to be the screen height minus this fixed LinerLayout height minus a little margin.</p>
  
  <p>I tried this:</p>
  
  <pre><code>(...)
  int scrollFInalHeight = scrollHeight - fixedMenuHeight - 10;
  
  ViewGroup.LayoutParams param = new ViewGroup.LayoutParams(scrollStartWidth, scrollFInalHeight);
  scroll.setLayoutParams(param);
  </code></pre>
  
  <p>But the app crashes when I start this activity.
  This java code is within the <strong>public void onWindowFocusChanged(boolean hasFocus)</strong> method.</p>
  
  <p>Any suggestions?
  Thanks in advance! ;)</p>