2017-07-26 61 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'属性,一切正常,因为它应该现在,谢谢! –