2017-07-26 36 views
1

我有一個允許創建動態EditText的佈局 - 此工作正常,但它推動了靜態EditTexts,這不是我想要的。動態活動開始時的佈局更改

我使用的是滾動視圖,所以理論上靜態的EditText應該固定到位,當添加動態EditTexts時,用戶可以向下滾動。

取而代之,隨着更多動態EditText被添加,3個靜態EditTexts開始越來越靠近。動態EditTexts中的間距很好,因爲它們都是同一個數組的一部分,但我似乎無法看到靜態EditTexts發生了什麼。

任何幫助,將不勝感激。

<?xml version="1.0" encoding="utf-8"?> 

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true"> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/linearLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/facebookBlue" 
     android:orientation="vertical" 
     android:weightSum="1" 
     tools:context="com.test.practise.AddTeamMembers"> 


     <android.support.design.widget.TextInputEditText 
      android:id="@+id/tv_teamNames" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:gravity="center" 
      android:text="@string/teamName" 
      android:textColor="@android:color/background_light" 
      android:textColorLink="@android:color/background_light" 
      android:textSize="30sp" 
      android:textStyle="bold" /> 


     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.26" 
      android:orientation="vertical" 
      android:weightSum="1"> 

      <TextView 
       android:id="@+id/textView3" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_weight="0.47" 
       android:gravity="center" 
       android:text="Enter Player Names Below!" 
       android:textColor="@android:color/background_light" 
       android:textSize="24sp" /> 

     </FrameLayout > 


     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.10" 
      android:orientation="vertical" 
      android:weightSum="1"> 

      <EditText 

       android:id="@+id/et_team_name1" 
       android:layout_width="232dp" 
       android:layout_height="37dp" 
       android:layout_gravity="center" 
       android:layout_marginBottom="0dp" 
       android:layout_weight="1" 
       android:background="@android:color/background_light" 
       android:ems="10" 
       android:hint="@string/PlayerName" 
       android:imeOptions="actionDone" 
       android:inputType="text" 
       android:paddingLeft="90dp" 
       tools:layout_editor_absoluteX="76dp" 
       tools:layout_editor_absoluteY="188dp" 
       /> 

     </FrameLayout> 

     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.10" 
      android:orientation="vertical" 
      android:weightSum="1"> 

      <EditText 
       android:id="@+id/et_team_name2" 
       android:layout_width="232dp" 
       android:layout_height="37dp" 
       android:layout_gravity="center" 
       android:layout_marginBottom="0dp" 
       android:layout_weight="1" 
       android:background="@android:color/background_light" 
       android:ems="10" 
       android:hint="@string/PlayerName" 
       android:imeOptions="actionDone" 
       android:inputType="text" 
       android:paddingLeft="90dp" 
       android:singleLine="true" 
       tools:layout_editor_absoluteX="76dp" 
       tools:layout_editor_absoluteY="188dp" 
       /> 

     </FrameLayout> 

     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="15dp" 
      android:layout_weight="0.10" 
      android:orientation="vertical" 
      android:weightSum="1"> 

      <EditText 
       android:id="@+id/et_team_name3" 
       android:layout_width="232dp" 
       android:layout_height="37dp" 
       android:layout_gravity="center" 
       android:layout_marginBottom="0dp" 
       android:background="@android:color/background_light" 
       android:ems="10" 
       android:hint="@string/PlayerName" 
       android:imeOptions="actionDone" 
       android:inputType="text" 
       android:paddingLeft="90dp" 
       android:singleLine="true" 
       tools:layout_editor_absoluteX="76dp" 
       tools:layout_editor_absoluteY="188dp" 
       android:layout_weight="1" 
       /> 

     </FrameLayout> 

     <LinearLayout 
      android:id="@+id/editTextGroupLayout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:gravity="center" 
      android:orientation="vertical"></LinearLayout> 

     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.07" 
      android:orientation="vertical" 
      android:weightSum="1"> 

      <TextView 
       android:id="@+id/tv_add_name" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:gravity="center" 
       android:text="+ Add Name" 
       android:textColor="@android:color/background_light" 
       android:textSize="16dp" /> 

     </FrameLayout > 


     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:weightSum="1"> 

      <Button 
       android:id="@+id/btn_submit_team" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:background="@color/facebookBlue" 
       android:gravity="center" 
       android:text="Ready to join!" 
       android:textColor="@android:color/background_light" /> 

     </FrameLayout > 


    </LinearLayout> 

</ScrollView> 

導致該

Before Dynamic EditText is added

After Dynamic EditText is added

+0

你爲什麼要將每個部件都包裹在FrameLayout中?這似乎沒用。 'android:orientation =「vertical」'對FrameLayout沒有任何作用。此外,你的佈局定義中有一個死亡的LinearLayout。嘗試從您的父LinearLayout和任何孩子中刪除'android:weightSum =「1」',您似乎沒有正確使用權重。 – CzarMatt

+0

嗯,當我使用線性佈局時,錯誤的方向留在了那裏 - 只是試驗。至於'死LinearLayout'這是在我的代碼中引用的動態EditText的一部分。 –

回答

1

這是很難沒有看到所有的代碼的說法,但我相信從使用的android:fillViewport您的問題源於您的ScrollViewandroid:layout_weight你的LinearLayout的孩子。

你的ScrollView的小孩,LinearLayout,有wrap_content身高。但是,由於ScrollView上的fillViewport屬性,您的LinearLayout將被拉伸以填滿屏幕。這意味着會有一些「額外」的高度。

layout_weight屬性將這個額外的高度分開,並將其中的一部分給予每個孩子。

當您動態地將EditText s添加到您的視圖中時,「額外」高度的數量會減少(直到沒有多餘的高度)。這具有將原始視圖靠得更近的視覺效果。

解決方案將取決於您想要達到的目標。我懷疑答案是您應該從視圖中刪除layout_weight屬性,而是使用邊距以可視方式分隔它們。

+0

是的,它是造成問題的'layout_weight'屬性,一切正常,因爲它應該現在,謝謝! –