我有一个几乎没有编辑文本的表单,下面有一个像这样的按钮 This is a form on fragment 它看起来很好,直到我打开键盘,即使应用了不同的属性(例如
),表单也不会调整自身大小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);
我还尝试了 list 和 fragment 布局,但大多数我都可以实现这一点 The buttons Comes Up Not EditText
这是我的 fragment 布局,其中 EditTexts
<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>
即使在布局文件和 list 中尝试 android:windowSoftInputMode="adjustPan|adjustResize"
后,我的布局也没有调整
最佳答案
“提交”按钮有 android:layout_alignParentBottom="true"
这使得它出现在键盘上方。您需要将其更改为适当的 layout_*
参数,将其放置在您真正想要的位置。事实上,您应该考虑使用 LinearLayout
或 TableLayout
以便将 subview 保留在您想要的位置。
关于java - Android-键盘打开时表单内容不调整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38901195/