Inflater swells, but the height is small (looks like wrap_content and requires fill_parent)

I have a layout and I want to inflate it

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
>
    <EditText
        android:id="@+id/editText1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    >       
    </EditText>

</LinearLayout>

like

    LinearLayout ll=(LinearLayout)findViewById(R.id.llContainer);
    View view; 
    LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    view = inflater.inflate(R.layout.question_free_text, null);
    ll.addView(view);

where ll

<LinearLayout
    android:id="@+id/llContainer"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginTop="20dp"
    android:layout_marginBottom="20dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
>
</LinearLayout>

in another xml, but the problem is when it inflates it, but the height is big (fill_parent, it looks like wrap_content, but there is no wrap_content in the layout). Can anybody help me?

+5
source share
1 answer

As Yashwanth Kumar correctly mentioned in the comments, the second parameter of the inflate method should be the root view into which the new view will be inserted:

LinearLayout ll = (LinearLayout) findViewById(R.id.llContainer);
View view;
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
view = inflater.inflate(R.layout.question_free_text, ll);

, LayoutInflator generateLayoutParams(ViewGroup.LayoutParams p) , LayoutParams ( , / ), .

, , root.addView(View child, LayoutParams params).

inflate (boolean attachToRoot), false, , LayoutParams setLayoutParams(params). , (, /):

LinearLayout ll = (LinearLayout) findViewById(R.id.llContainer);
View view;
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
view = inflater.inflate(R.layout.question_free_text, ll, false); // the LayoutParams of view are set here
ll.addView(view, 2);
+14
source

All Articles