Вопрос

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>
Это было полезно?

Решение

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

Другие советы

-----
android:layout_height="match_parent" >
mlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/IngredientsLineSwitcher"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView 
    android:id="@+id/IngredientsLineText"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
  ----
<EditText
    android:id="@+id/IngredientsLineEdit"
    android:layout_height="match_parent"
    android:layout_width="match_parent"      
   -----

Change from fill_parent to match_parent in all Views.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top