Views are not visible after addView
<p>This is the dynamically created view:</p>

<pre><code>&lt;ScrollView 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;LinearLayout
        android:id="@+id/linearlayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="@color/colorPrimary"
        android:minHeight="50dp"&gt;
    &lt;/LinearLayout&gt;
&lt;/ScrollView&gt;
</code></pre>

<p>I add views to LinearLayout above with codes similar to following :</p>

<pre><code> View view = inflater.inflate(R.layout.somelayout, rootView, false);
 AppCompatTextView textView = (AppCompatTextView) view.findViewById(R.id.text);
 textView.setText("Text");
 AppCompatTextView textView2 = (AppCompatTextView) view.findViewById(R.id.text2);
 textView2.setText("Text");
 view.setLayoutParams(vp);
 rootView.addView(view);
</code></pre>

<p>vp is the following:</p>

<pre><code>LinearLayout.LayoutParams vp =
    new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
        LinearLayout.LayoutParams.WRAP_CONTENT);
</code></pre>

<p>In some cases views are added but not visible.Even i can scroll the layout. Initial state of the container layout is invisible. I add views and then set visibility to VISIBLE when clicked a tab. When i change the orientation, they become visible. When they are not visible, i checked with hierarchy viewer and saw that child views measurements are 0. I call requestlayout and also invalidate, but doesnt work. How can i force to measure child views?</p>