【发布时间】:2018-02-15 21:35:36
【问题描述】:
目前,我有一些带有多个 Textview 的 Android xml 布局,可以输入数据。相对布局的底部是一个属性为android:layout_alignParentBottom="true" 的按钮,带有文本“保存更改”,预计在键盘弹出时显示在键盘上方。
但是,当单击列表底部的文本视图时,一旦获得焦点,“保存更改”按钮就会与焦点所在的文本视图重叠。
注意:可以自己手动向下滚动一点,然后查看 Textview。
理想情况下,此处的功能是调整 scrollTo() 以有效地滚动到焦点元素并将其置于“保存更改”按钮上方的视图中。
我已尝试在清单的活动属性中设置此值:
android:windowSoftInputMode="adjustResize"
将相对布局包装在 LinearLayout 中,或在 ScrollView 底部添加填充均无济于事。
这是我当前的 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>
在键盘上方仍然显示“保存更改”按钮的同时滚动到焦点文本视图的最佳方式是什么?
非常感谢任何想法!
【问题讨论】:
标签: android xml android-layout android-softkeyboard