我有一个允许创建动态EditText的布局 - 这样可以正常工作,但它会推动静态的EditTexts,这不是我想要的。
我正在使用scrollview,所以理论上静态EditText应该锚定到位,当添加动态EditTexts时,用户可以向下滚动。
相反,随着更多动态EditTexts的添加,我开始越来越接近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>
这导致了这个
答案 0 :(得分:1)
很难说没有看到您的所有代码,但我相信您的问题源于android:fillViewport
ScrollView
和android:layout_weight
LinearLayout
的孩子们。
ScrollView
的{{1}}儿童身高LinearLayout
。但是,由于wrap_content
上的fillViewport
属性,您的ScrollView
将被拉伸以填充屏幕。这意味着将有一些“额外”的高度。
LinearLayout
属性将额外的高度分开,并将其中的一些给予每个孩子。
当您向视图中动态添加layout_weight
时,“额外”的高度会减少(直到没有额外的高度)。这具有将原始视图推得越来越近的视觉效果。
解决方案将取决于您想要实现的目标。我怀疑答案是你应该从视图中删除EditText
属性,而是使用边距将它们视觉分开。