我有一个允许创建动态 EditText 的布局 - 这工作正常,但它推高了静态 EditTexts 这不是我想要的。
我使用的是滚动视图,所以理论上静态 EditText 应该锚定到位,当添加动态 EditTexts 时,用户可以向下滚动。
相反,随着更多动态 EditText 的添加,我开始将 3 个静态 EditText 越来越靠近。动态 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>
这导致了这个
It is hard to say without seeing all of your code, but I believe your problem stems from the use of android:fillViewport
on your ScrollView
and android:layout_weight
on your LinearLayout
's children.
Your ScrollView
's child, the LinearLayout
, has wrap_content
height. However, due to the fillViewport
attribute on the ScrollView
, your LinearLayout
will be stretched to fill the screen. This means there is going to be some "extra" height.
The layout_weight
attributes divide up that extra height, and give some of it to each child.
As you dynamically add EditText
s to your view, the amount of height that is "extra" is reduced (until there is no extra height). This has the visual effect of pushing your original views closer and closer together.
解决方案将取决于您想要实现的目标。我怀疑答案是您应该layout_weight
从视图中删除属性,而是使用边距在视觉上将它们分开。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句