Android 显示键盘上方的按钮
我做了一个注册表,里面有两个按钮。现在我想要的是,当显示键盘时,底部的两个按钮应该显示在键盘上方,而不是隐藏在键盘下方。为了实现这一点,我编写的代码没有给我任何成功 Xml代码Android 显示键盘上方的按钮,android,android-layout,Android,Android Layout,我做了一个注册表,里面有两个按钮。现在我想要的是,当显示键盘时,底部的两个按钮应该显示在键盘上方,而不是隐藏在键盘下方。为了实现这一点,我编写的代码没有给我任何成功 Xml代码 <LinearLayout android:layout_height="match_parent" android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:inputType="textPersonName"
style="@style/EditText"
android:hint="@string/firstname"
android:id="@+id/et_first_name" />
<EditText
android:inputType="textPersonName"
style="@style/EditText"
android:hint="@string/lastname"
android:id="@+id/et_last_name" />
<Button
style="@style/EditText"
android:text="@string/country"
android:id="@+id/bt_country" />
<Button
style="@style/EditText"
android:text="@string/gender"
android:id="@+id/bt_gender" />
<EditText
style="@style/EditText"
android:inputType="phone"
android:hint="@string/mobileno"
android:id="@+id/et_mobile_no" />
<EditText
style="@style/EditText"
android:inputType="textEmailAddress"
android:hint="@string/email"
android:id="@+id/et_email" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
style="@style/EditText"
android:id="@+id/bt_reg_cancel"
android:text="@string/cancel"
android:layout_gravity="bottom"
android:layout_weight="1" />
<Button
style="@style/EditText"
android:text="@string/save"
android:id="@+id/bt_reg_save"
android:layout_gravity="bottom"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
请在Android清单中提供帮助,提供属性Android:WindowsOfInputMode=“adjustResize”。这将在键盘显示时调整布局 因此,如果底部有东西,一旦显示出来,它就会显示在键盘上方 “请给我看一下相关布局的代码,这会很有帮助吗?”–7分钟前的用户3917131“ 解决方案:-
3.)删除scrollview,改为使其线性布局。使顶部父级相对布局,并将属性align Parent bottom true设置为底部布局,将Layout above属性设置为linearlayout例如,您应该将ScrollView的leyout_权重设置为1。并将线性布局的放样高度设置为“包裹内容”。将ScrollView的布局高度设置为0dp会很好,这样LinearLayout就可以管理它的高度
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
<ScrollView
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp">
</ScrollView>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
style="@style/EditText"
android:id="@+id/bt_reg_cancel"
android:text="@string/cancel"
android:layout_gravity="bottom"
android:layout_weight="1" />
<Button
style="@style/EditText"
android:text="@string/save"
android:id="@+id/bt_reg_save"
android:layout_gravity="bottom"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
这应该能奏效 为什么不使用scroll view?将您的按钮放在scroll view中,然后尝试……我想保持按钮的位置固定在manifiest android中的活动声明中使用此参数:WindowsOfInputMode=“adjustResize”。因为您的整个布局都在scroll view中,所以它无法工作。因为您可以滚动,所以它不会调整大小。删除scrollview,它将工作整个布局在编译时不在scroll视图中,不知道您的布局是否在底部。它位于底部,因为您的scrollview中有许多子视图。如果您的scrollview中只有一个子项,那么底部布局将不会位于底部。要么将主父项设置为relativelayout,要么将align parent bottom设置为True我修改了答案并提供了三种方法,但没有提供完整的代码