AlignParentBottom 按钮在 Scroll/Focus 上与 Textview 重叠
AlignParentBottom button overlaps Textview on Scroll/Focus
目前,我有几个 Android xml 布局,其中包含多个可以输入数据的文本视图。相对布局的底部是一个按钮,属性为android:layout_alignParentBottom="true"
,文本为"Save Changes",希望在键盘弹出时显示在键盘上方。
但是,当单击列表底部的文本视图时,一旦聚焦,"Save Changes" 按钮就会与聚焦的文本视图重叠。
注意:您可以自己手动向下滚动一点,然后查看 Textview。
理想情况下,此处的功能是调整 scrollTo() 以有效地滚动到焦点元素并将其放置在 "Save Changes" 按钮上方的视图中。
我试过在清单的活动属性中设置这个值:
android:windowSoftInputMode="adjustResize"
在 LinearLayout 中包装 RelativeLayout,或在 ScrollView 的底部添加 padding 都无济于事。
这是我当前的 XML,不包括标题栏:
<ScrollView
android:id="@+id/edit_info_section"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:layout_below="@id/activity_title_border_bottom">
<LinearLayout
android:id="@+id/edit_info_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/huge_padding"
android:layout_marginBottom="@dimen/huge_padding">
<TextView
android:id="@+id/account_firstname_label"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/label_firstname"
style="@style/label_text"/>
<EditText
android:id="@+id/account_firstname_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:maxLines="1"
style="@style/EditTextStyle" />
<TextView
android:id="@+id/account_lastname_label"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/label_lastname"
style="@style/label_text"/>
<EditText
android:id="@+id/account_lastname_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:maxLines="1"
style="@style/EditTextStyle" />
<TextView
android:id="@+id/account_phone_label"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/label_phone"
style="@style/label_text"/>
<EditText
android:id="@+id/account_phone_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="phone"
android:maxLines="1"
style="@style/EditTextStyle" />
<TextView
android:id="@+id/account_email_label"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/label_email"
style="@style/label_text"/>
<EditText
android:id="@+id/account_email_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textEmailAddress"
android:maxLines="1"
android:layout_marginBottom="@dimen/activity_vertical_margin"
style="@style/EditTextStyle" />
<TextView
android:id="@+id/account_password_label"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/label_password"
style="@style/label_text"/>
<EditText
android:id="@+id/account_password_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword"
android:maxLines="1"
android:layout_marginBottom="@dimen/activity_vertical_margin"
style="@style/EditTextStyle" />
</LinearLayout>
</ScrollView>
<Button
android:id="@+id/save_changes"
android:background="@drawable/button_background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="@string/save_changes"
android:textColor="@color/White"
android:textStyle="bold"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingTop="@dimen/activity_vertical_margin"
style="style/Widget.AppCompat.Button.Colored"/>
</RelativeLayout>
滚动到焦点文本视图的最佳方式是什么,同时仍然在键盘上方显示 "Save changes" 按钮?
非常感谢任何想法!
看起来你的布局大约是:
<RelativeLayout>
<ScrollView>
...
</ScrollView>
<Button/>
</RelativeLayout>
此结构的问题在于 ScrollView
填满了整个屏幕。换句话说,ScrollView
的一部分总是 "behind" Button
... 只有当键盘出现时才会出现问题。 =17=]
相反,我认为你应该使用这种布局:
<LinearLayout
android:orientation="vertical"
...>
<ScrollView
android:layout_height="0dp"
android:layout_weight="1"
...>
...
</ScrollView>
<Button/>
</LinearLayout>
通过这样做,您可以确保 ScrollView
中的内容不可能位于按钮后面,但您仍然可以将 Button
一直推到屏幕底部.
目前,我有几个 Android xml 布局,其中包含多个可以输入数据的文本视图。相对布局的底部是一个按钮,属性为android:layout_alignParentBottom="true"
,文本为"Save Changes",希望在键盘弹出时显示在键盘上方。
但是,当单击列表底部的文本视图时,一旦聚焦,"Save Changes" 按钮就会与聚焦的文本视图重叠。
注意:您可以自己手动向下滚动一点,然后查看 Textview。
理想情况下,此处的功能是调整 scrollTo() 以有效地滚动到焦点元素并将其放置在 "Save Changes" 按钮上方的视图中。
我试过在清单的活动属性中设置这个值:
android:windowSoftInputMode="adjustResize"
在 LinearLayout 中包装 RelativeLayout,或在 ScrollView 的底部添加 padding 都无济于事。
这是我当前的 XML,不包括标题栏:
<ScrollView
android:id="@+id/edit_info_section"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:layout_below="@id/activity_title_border_bottom">
<LinearLayout
android:id="@+id/edit_info_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/huge_padding"
android:layout_marginBottom="@dimen/huge_padding">
<TextView
android:id="@+id/account_firstname_label"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/label_firstname"
style="@style/label_text"/>
<EditText
android:id="@+id/account_firstname_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:maxLines="1"
style="@style/EditTextStyle" />
<TextView
android:id="@+id/account_lastname_label"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/label_lastname"
style="@style/label_text"/>
<EditText
android:id="@+id/account_lastname_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:maxLines="1"
style="@style/EditTextStyle" />
<TextView
android:id="@+id/account_phone_label"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/label_phone"
style="@style/label_text"/>
<EditText
android:id="@+id/account_phone_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="phone"
android:maxLines="1"
style="@style/EditTextStyle" />
<TextView
android:id="@+id/account_email_label"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/label_email"
style="@style/label_text"/>
<EditText
android:id="@+id/account_email_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textEmailAddress"
android:maxLines="1"
android:layout_marginBottom="@dimen/activity_vertical_margin"
style="@style/EditTextStyle" />
<TextView
android:id="@+id/account_password_label"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/label_password"
style="@style/label_text"/>
<EditText
android:id="@+id/account_password_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword"
android:maxLines="1"
android:layout_marginBottom="@dimen/activity_vertical_margin"
style="@style/EditTextStyle" />
</LinearLayout>
</ScrollView>
<Button
android:id="@+id/save_changes"
android:background="@drawable/button_background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="@string/save_changes"
android:textColor="@color/White"
android:textStyle="bold"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingTop="@dimen/activity_vertical_margin"
style="style/Widget.AppCompat.Button.Colored"/>
</RelativeLayout>
滚动到焦点文本视图的最佳方式是什么,同时仍然在键盘上方显示 "Save changes" 按钮?
非常感谢任何想法!
看起来你的布局大约是:
<RelativeLayout>
<ScrollView>
...
</ScrollView>
<Button/>
</RelativeLayout>
此结构的问题在于 ScrollView
填满了整个屏幕。换句话说,ScrollView
的一部分总是 "behind" Button
... 只有当键盘出现时才会出现问题。 =17=]
相反,我认为你应该使用这种布局:
<LinearLayout
android:orientation="vertical"
...>
<ScrollView
android:layout_height="0dp"
android:layout_weight="1"
...>
...
</ScrollView>
<Button/>
</LinearLayout>
通过这样做,您可以确保 ScrollView
中的内容不可能位于按钮后面,但您仍然可以将 Button
一直推到屏幕底部.