2

我使用ViewSwitcher允許從TextView切換到EditText元素。我注意到EditText元素在視圖底部產生了額外的填充(例如,如果我刪除了EditText,所有內容看起來都像預期的那樣,但是添加它,即使可見性設置消失,底部也會產生額外的空間) 。這是什麼原因造成的?應該如何解決?ViewSwitcher與EditText留下額外的填充

<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> 

回答

1

你應該把一個RelativeLayout圍繞TextViewEditText控制自己的定位。

1
----- 
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"  
    ----- 

在所有視圖中從fill_parent更改爲match_parent。