Java Android-打开键盘时不调整表单内容
我有一个表单,它几乎没有编辑文本,下面是这样的按钮 它看起来很好,直到我打开键盘,表单甚至在应用了不同的属性之后也不会调整自身大小Java Android-打开键盘时不调整表单内容,java,android,user-interface,android-fragments,view,Java,Android,User Interface,Android Fragments,View,我有一个表单,它几乎没有编辑文本,下面是这样的按钮 它看起来很好,直到我打开键盘,表单甚至在应用了不同的属性之后也不会调整自身大小 getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN |WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE ); getActivity().getWindow().setSoftI
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN |WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE );
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE );
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE |WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE );
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE |WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN );
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_MODE_CHANGED);
我还尝试了清单和片段布局,但大部分我都能做到这一点
这是我的片段布局,编辑文本在哪里
<ScrollView android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fitsSystemWindows="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
>
<android.support.design.widget.TextInputLayout
android:layout_height="wrap_content"
android:layout_width="185dp"
android:id="@+id/view"
android:layout_below="@+id/Uploader"
android:layout_alignLeft="@+id/view4"
android:layout_alignStart="@+id/view4"
android:fitsSystemWindows="true"
android:layout_marginTop="58dp">
<EditText
android:layout_width="175dp"
android:layout_height="wrap_content"
android:id="@+id/first_Name"
android:drawableLeft="@drawable/ic_perm_identity_black_24dp"
android:inputType="textPersonName"
android:textColor="#000"
android:hint="First Name"
android:layout_alignTop="@+id/last_Name" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="185dp"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:layout_alignTop="@+id/view"
android:layout_toRightOf="@+id/view"
android:layout_toEndOf="@+id/view"
android:id="@+id/view2">
<EditText
android:layout_width="175dp"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_perm_identity_black_24dp"
android:id="@+id/last_Name"
android:inputType="textPersonName"
android:hint="Last Name" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:layout_marginRight="15dp"
android:layout_marginLeft="15dp"
android:layout_below="@+id/view2"
android:layout_alignRight="@+id/view2"
android:layout_alignEnd="@+id/view2"
android:id="@+id/view3">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/phone"
android:inputType="phone"
android:hint="Enter Phone Number"
android:drawableLeft="@drawable/ic_call_black_24dp"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:layout_below="@+id/view3"
android:layout_marginRight="15dp"
android:layout_marginLeft="15dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/view4">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/mailID"
android:drawableLeft="@drawable/ic_email_black_24dp"
android:inputType="textEmailAddress"
android:hint="Enter Email Address"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:layout_marginRight="15dp"
android:layout_marginLeft="15dp"
android:layout_below="@+id/view4"
android:layout_alignRight="@+id/view2"
android:layout_alignEnd="@+id/view2"
android:id="@+id/view6">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/password"
android:drawableLeft="@drawable/ic_lock_black_24dp"
android:inputType="textVisiblePassword"
android:hint="Enter Password"
/>
</android.support.design.widget.TextInputLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fitsSystemWindows="false"
android:id="@+id/Submit"
android:text="SUBMIT"
android:layout_gravity="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="74dp" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:background="@drawable/ic_add_a_photo_black_48dp"
android:id="@+id/Uploader"
android:layout_marginTop="84dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/Image_Preview"
android:layout_toLeftOf="@+id/Uploader"
android:layout_toStartOf="@+id/Uploader"
android:layout_alignBottom="@+id/Uploader" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sign In"
android:textSize="25dp"
android:id="@+id/regUser"
android:layout_alignParentTop="true"
android:layout_alignRight="@+id/view3"
android:layout_alignEnd="@+id/view3" />
</RelativeLayout>
</ScrollView>
即使在布局文件和清单中尝试了android:WindowsOfInputMode=“adjustPan | adjustResize”,“提交”按钮也没有进行调整,因为它显示在键盘上方。您需要将其更改为适当的
layout.*
param,将其放置在您实际需要的位置。事实上,你应该考虑使用<代码>线性布局< /代码>或<代码> TabelayayOuts<代码>,以便让孩子看到你想要的位置。 < P>“提交”按钮有<代码> Android:LayOutoTracePaleNealTe=“true”< /Cord>这就是它出现在键盘之上的原因。您需要将其更改为适当的layout.*
param,将其放置在您实际需要的位置。事实上你应该考虑使用<代码>线性布局<代码> >或代码> TabelayayOut/<代码>,以便让孩子看到你想要的东西。你希望布局看起来像什么?@代码学徒你能检查两个你想知道我想要达到的图像吗?在第二个图像中,你可以看到只有提交按钮在键盘上。整个表单,所以当键盘打开时,我希望所有编辑文本和按钮都应位于上方。是否希望视图向上滚动,以便看到更多编辑文本?或者,当键盘在屏幕上时,您希望布局适合可用区域中的所有编辑文本吗?@Code peedient向上滚动,以便我可以在滚动屏幕时看到所有编辑文本框我不希望在键盘打开后,编辑文本在可用布局中收缩open@Code-学徒即使在ScrollVIew之后,我的按钮也会出现在最后一个编辑文本中,如中所示上图显示的是键盘上方的“提交”按钮。请检查编辑后的布局您希望布局是什么样子?@Code学徒您能检查两张图像吗?您会知道我想要实现什么,在链接的第二张图像中,您可以看到只有“提交”按钮位于键盘上方,而不是整个表单,因此我希望所有编辑文本和按钮都位于上方当键盘打开时,是否希望视图向上滚动,以便看到更多的编辑文本?或者,当键盘在屏幕上时,您希望布局适合可用区域中的所有编辑文本吗?@Code peedient向上滚动,以便我可以在滚动屏幕时看到所有编辑文本框我不希望在键盘打开后,编辑文本在可用布局中收缩open@Code-学徒即使在ScrollVIew之后,我的按钮也会出现在最后一个编辑文本中,如中所示上图显示的是键盘上方的“提交”按钮。请检查编辑的布局并检查其效果,我将marginTop=425dp设置为与上次编辑的下方对齐text@KabirRaz最好使用下面的android:layout_而不是这么大的边距。这将在不同的设备大小之间更具可移植性。当我在上面的布局文件android:layout_lower=“@+id/password”
中使用任何布局属性时,它显示@+id/password不是同一相对位置的同级,因此我必须使用margin@KabirRaz密码编辑文本包含在TextInputLayout
中。如果你给这个TextInputLayout
一个id,你可以将它用于下面的layout\u
。感谢它的工作,我将marginTop=425dp设置为与上次编辑的下方对齐text@KabirRaz最好使用下面的android:layout_而不是这么大的边距。这将在不同的设备大小之间更具可移植性。当我在上面的布局文件android:layout_lower=“@+id/password”
中使用任何布局属性时,它显示@+id/password不是同一相对位置的同级,因此我必须使用margin@KabirRaz密码编辑文本包含在TextInputLayout
中。如果您给这个TextInputLayout
一个id,您可以将它用于下面的layout\u
。