This is the dynamically created view:
<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">
<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">
</LinearLayout>
</ScrollView>
I add views to LinearLayout above with codes similar to following :
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);
vp is the following:
LinearLayout.LayoutParams vp =
new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
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?