【问题标题】:Android- Content of forms not adjusting when keyboard opensAndroid-键盘打开时表单内容不调整
【发布时间】:2016-08-11 16:01:13
【问题描述】:

我有一个表单,它的编辑文本很少,下面有这样的按钮 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);

我也在清单和片段布局中尝试过,但大部分我都可以做到这一点 The buttons Comes Up Not EditText

这是我的片段布局,其中 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>

即使在布局文件和清单中尝试android:windowSoftInputMode="adjustPan|adjustResize" 后,我的布局也没有调整

【问题讨论】:

  • 您希望布局是什么样的?
  • @Code-Apprentice 你能检查两个图像你会知道我想要实现什么,在链接中的第二个图像中你可以看到只有提交按钮在键盘上方而不是整个表单所以我想要所有编辑文本当键盘打开时,按钮应该在上方
  • 您想让视图向上滚动以便看到更多的编辑文本吗?或者当键盘在屏幕上时,您是否希望布局适合可用区域中的所有编辑文本?
  • @Code-Apprentice 向上滚动,这样我可以在滚动屏幕时看到所有编辑文本框,我不希望我的编辑文本在键盘打开后缩小为可用布局
  • @Code-Apprentice 即使在 ScrollVIew 我的按钮出现在最后一个编辑文本之后,如上图所示,我在键盘上方提交按钮。请检查编辑后的布局

标签: java android user-interface android-fragments view


【解决方案1】:

“提交”按钮有android:layout_alignParentBottom="true",这就是它出现在键盘上方的原因。您需要将其更改为适当的 layout_* 参数,将其放置在您真正想要的位置。事实上,您应该考虑使用LinearLayoutTableLayout 以便将子视图保持在您想要的位置。

【讨论】:

  • 感谢它的工作,我将 marginTop=425dp 设置为在最后一个编辑文本的下方对齐
  • @KabirRaz 使用android:layout_below 可能比使用这么大的余量更好。这将在不同的设备尺寸上更便携。
  • 当我在上面的布局文件android:layout_below="@+id/password" 中使用任何布局属性时,它显示@+id/password 不是同一个relativelayout 中的兄弟,所以我必须使用边距
  • @KabirRaz 密码 EditText 包含在 TextInputLayout 中。如果你给这个 TextInputLayout 一个 id,你可以将它用于 layout_below
猜你喜欢
  • 2017-09-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多