jeudi 7 mai 2015

If a parent view has width set to WRAP_CONTENT, will it be updated if its child view is changed at runtime?

My question is: If I set my parent layout to wrap_content, and the child view changes size somewhere during the execution, should my parent layout also change size?

I assumed yes, but my dialog behavior shows otherwise. That being said, it's very possible that something else is happening (I am not original writer).

More context: I have an alert dialog that contains two buttons and an edittext. The edittext will expand with every line until it reaches five lines.

Expected: Dialog expands when the edittext expands

Actual: Dialog does not expand; edittext expands and pushes buttons down such that they are clipped

Here is a simplified snippet to show what I am talking about

<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
  <EditText
  android:id="@+id/inputbox"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"/>

  <LinearLayout
  android:orientation="horizontal"
  android:layout_width="wrap_content"
  android:layout_height="@dimen/someheight"
  android:gravity="center"
  android:layout_gravity="center_horizontal" >

  <Button
      android:id="@+id/negative_button"
      android:layout_width="@dimen/somewidth"
      android:layout_height="match_parent"
      android:text="@string/TXT_CANCEL"/>

  </LinearLayout>
</LinearLayout>

Aucun commentaire:

Enregistrer un commentaire