Search code examples
android-layoutandroid-edittextandroidviewswitcher

ViewSwitcher with EditText leaves extra padding


I'm using a ViewSwitcher to allow switching from a TextView to an EditText element. What I've noticed is that the EditText element generates extra padding at the bottom of the view (i.e. if I remove the EditText everything looks as expected, but adding it, even when visibility is set to gone, generates extra space at the bottom). What's causing this and how should it be resolved?

<ViewSwitcher
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/IngredientsLineSwitcher"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
    <TextView 
        android:id="@+id/IngredientsLineText"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:paddingBottom="0dip"
        android:paddingLeft="10dip"
        android:paddingTop="0dip"
        android:text=""
        android:textColor="@color/black"
        android:textSize="@dimen/recipe_label_font_size" />
    <EditText
        android:id="@+id/IngredientsLineEdit"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"      
        android:paddingBottom="0dip"
        android:paddingLeft="10dip"
        android:paddingTop="0dip"
        android:text=""
        android:visibility="gone"
        android:textColor="@color/black"
        android:textSize="@dimen/recipe_label_font_size" /> 
</ViewSwitcher>

Solution

  • You should put a RelativeLayout around the TextView or EditText to control their positioning.