Android,在编辑文本中进行输入时,防止相对布局底部对齐的按钮上升

标签 android android-relativelayout

我创建了一个包含 3 个 ListView 的相对布局。在顶部我有一个 editText 字段。中间有一个 ScrollView ,可以填充所有剩余空间。在底部我放置了一个按钮。问题是,当我在 editText 字段中进行输入时,键盘出现,然后按钮被移动并放置在键盘上。看起来按钮总是粘在“左” View 的底部,但我希望它保留在原始窗口的底部。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/ll_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
    >

        <TextView
            android:id="@+id/tv_course_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/text_view_course_name"
            android:textStyle="bold" />

        <EditText
            android:id="@+id/et_course_name"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll_save_course_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:onClick="saveCourse"
            android:text="@string/button_save_course" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll_course_table"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/ll_save_course_button"
        android:layout_below="@id/ll_name" >

    </LinearLayout>


</RelativeLayout>

最佳答案

在你的 list 文件中,

        <activity
        android:name=".HomeActivity"
        android:windowSoftInputMode="stateHidden|adjustPan" >

注意: 在这里,我使用了 HomeActivity,您需要指定要在其中设置上述布局 xml 文件的 Activity 名称。

关于Android,在编辑文本中进行输入时,防止相对布局底部对齐的按钮上升,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14661896/

相关文章:

android - 角色 ACL 无法使用 Parse 的 Android 本地数据存储 :

android - 从 Firebase 数据库检索数据并将其设置到 recyclerview 适配器中

android - 设置 View 的 X 和 Y onclick 不改变位置

android - 如何以编程方式设计此布局?

java - 如何在 android 中以编程方式将 TextViews 数组添加到相对布局中而不重叠?

java - Retrofit2 - 将图像上传到服务器,在 android studio 中给出内部服务器错误作为响应

java - 从 android 应用程序转换的黑莓 10 应用程序的 javascript 调用 java 函数

java - java 中 Class<T[]> 的实例,以便在 json 解析器中使用

android - 如何在随机屏幕位置显示按钮

android - 在 Android 中以编程方式在当前相对布局下方添加相对布局