title: Dynamically change View Stub layout_height attribute?
body: <p>I am using <strong>view stub</strong> in my application. I am inflating the <strong>view stub</strong> to the layout and it is working fine. Now if you see the <strong>dummy_layout.xml</strong> there I have given the <strong>android:layout_height=20dp</strong>. What I need to do is to <strong>change that view stub height from 20 dp to Wrap_Content</strong> on a button click. How can I achieve this?</p>
  
  <p>My ultimate goal is this. I have a button in it. when i click on it for first time I need to show the full layout of stub. and again when I click on it for the second time I need to animate the stub to slide down and show only a part of it. </p>
  
  <p><strong>dummy_layout.xml</strong>
      </p>
  
  <pre><code>    &lt;RelativeLayout
          android:id="@+id/topLayout"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content" &gt;
  
              &lt;ImageView
                  android:id="@+id/imageView1"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_alignParentLeft="true"
                  android:layout_alignParentRight="true"
                  android:layout_alignParentTop="true"
                  android:src="@drawable/ic_watch_pic" /&gt;
  
              &lt;Button
                  android:id="@+id/button1"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_alignParentLeft="true"
                  android:layout_alignParentTop="true"
                  android:background="@color/dark_grey"
                  android:text="Button" /&gt;
  
              &lt;Button
                  android:id="@+id/button2"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_alignParentRight="true"
                  android:layout_alignParentTop="true"
                  android:text="Button" /&gt;
  
      &lt;/RelativeLayout&gt;
  
      &lt;ViewStub
          android:id="@+id/viewStub1"
          android:layout="@layout/stub_layout"
          android:layout_width="wrap_content"
          **android:layout_height="20dp"**
          android:layout_alignParentBottom="true"/&gt;
  
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>And here is my class:    </p>
  
  <pre><code>public class DummyFragment extends Fragment {
  
      private View mRootView;
      private Context mContext;
      private Button mButton;
      private boolean isVisible = true;
      private RelativeLayout mParentLayout;
  
      @Override
      public View onCreateView(final LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
  
          mRootView = inflater.inflate(R.layout.dummy_layout,
                  container, false);
  
          mContext = getActivity();
  
          mButton = (Button) mTopLayout.findViewById(R.id.button1);
  
          final ViewStub stub = (ViewStub) mRootView.findViewById(R.id.viewStub1);
  
              **final View inflated = stub.inflate();**
  
          inflated.setVisibility(View.VISIBLE);
  
          final View viewstublayout = mRootView.findViewById(R.id.viewStub1);
  
          mButton.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
  
                  if(isVisible)
                  {
                      isVisible=false;    
                      inflated.setVisibility(View.VISIBLE);
                  }
                  else
                  {
                      isVisible=true;                     
                      inflated.setVisibility(View.INVISIBLE);
                  }
              }
          });
  
          return mRootView;
      }
  
  }
  </code></pre>