软键盘背后的Android隐藏布局按钮

标签 android android-activity layout

我正在开发一个需要用户输入一些单词的应用程序。但是一旦键盘打开,布局底部的布局按钮就会留在软键盘后面。

我的应用在这里

enter image description here

我需要我的按钮在软键盘打开时保持显示。

enter image description here

这是我的布局资源文件:

<FrameLayout 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:background="#d3d3d3" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="top"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/llWord"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/lblWord"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:padding="5dp"
            android:text="@string/string_word"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#555555" />

        <EditText
            android:id="@+id/txtWord"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:ems="10"
            android:hint="@null"
            android:text="@null"
            android:textColor="#000000" >
        </EditText>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/llInfo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/lblInfo"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:padding="5dp"
            android:text="@null"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#555555" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/llMeaning"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingTop="20dp" >

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:padding="5dp"
            android:text="@string/string_meaning"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#555555" />

        <EditText
            android:id="@+id/txtMeaning"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:ems="10"
            android:hint="@null"
            android:text="@null"
            android:textColor="#000000" >
        </EditText>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/llSynonyms"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:padding="5dp"
            android:text="@string/string_synonyms"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#555555" />

        <EditText
            android:id="@+id/txtSynonyms"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:ems="10"
            android:hint="@null"
            android:text="@null"
            android:textColor="#000000" >
        </EditText>
    </LinearLayout>
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/btnShow"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginRight="0.5dp"
        android:layout_weight="1"
        android:background="@drawable/btn"
        android:drawableLeft="@drawable/ic_action_undo"
        android:paddingLeft="15dp"
        android:text="@string/action_show"
        android:textColor="#d3d3d3" />

    <Button
        android:id="@+id/btnTrue"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginRight="0.5dp"
        android:layout_weight="1"
        android:background="@drawable/btn"
        android:drawableLeft="@drawable/ic_action_accept"
        android:paddingLeft="15dp"
        android:text="@string/action_true"
        android:textColor="#d3d3d3" />

    <Button
        android:id="@+id/btnFalse"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/btn"
        android:drawableLeft="@drawable/ic_action_remove"
        android:paddingLeft="15dp"
        android:text="@string/action_false"
        android:textColor="#d3d3d3" />
</LinearLayout>

最佳答案

转到 AndroidManifest.xml ,将其添加到您的 Activity 声明中:

android:windowSoftInputMode="adjustResize"

关于软键盘背后的Android隐藏布局按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35538339/

相关文章:

java - 为什么 onAttach 不能识别正确的 instanceof 上下文?

java - 像 Android Gmail 一样更新监听器

ios - 底部标签栏上方的间隙 - 嵌入式 NavigationController + 嵌入式 TableViewController

html - Chrome 搞乱了网站布局,FF 和 IE 都不错

android - 在另一个类中获取变量形式的自定义适配器

android - 根据所选项目 ViewModel 类型选择 fragment View

java - Android - 为什么使用接口(interface)被认为是 Activity 和 Fragment 之间通信的最佳实践?

layout - 什么软件用于编写真实世界的 haskell?

Android ffmpeg0.8 不能用 android ndk5 和 cygwin 编译器编译

java - Android java的正则表达式提取数字和特定符号