【问题标题】:Android - A blank space remains when the keyboard disappearsAndroid - 键盘消失时仍然存在空白
【发布时间】:2015-05-07 05:02:36
【问题描述】:

我遇到了键盘问题。当它消失时,它所占据的空间仍然是空白,其余的布局没有调整

普通屏幕:

带键盘:

键盘关闭:

我以前从未见过这个,所以我什至不知道从哪里开始寻找。这发生在 4.2.2 和 5.1

另一条重要信息是,这是一个包含所有内容的自定义 LinearLayout。也许与此有关。如果需要,我可以上传任何代码。

这是主要的布局文件外壳。

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

<!-- Menu (Drawer)-->
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:visibility="visible"
    android:layout_height="match_parent"
    android:orientation="vertical" >
     <ScrollView
        android:id="@+id/activity_main_menu_listview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/drawer_background"
        android:cacheColorHint="#00000000" >
     </ScrollView>
</LinearLayout>
<!-- Fragment Holder -->
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <!-- This is where fragment will show up -->
    <FrameLayout
        android:id="@+id/fragment_master"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </FrameLayout>
</LinearLayout>

这是我的清单文件

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MasterActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

【问题讨论】:

  • 也发布您的代码。
  • 你在听软键盘的开/关操作吗?
  • 同时发布您的清单文件。如果您使用android:windowSoftInputMode="adjustResize",这是所有布局调整大小的效果,但存在半透明/透明的问题...
  • @AnkitBansal 这只是一个基本的键盘,没有做任何花哨的打开/关闭操作
  • @eee 清单中没有关于 windowSoftInputMode 的内容。 “adjustResize”是默认的吗?

标签: android android-softkeyboard soft-keyboard


【解决方案1】:

我加了

android:windowSoftInputMode="adjustPan"

到我的活动标签中的清单,现在它可以工作了。我以前从来没有这样做过,我猜我的自定义布局不知何故弄乱了键盘。

感谢@eee 评论为我指明了正确的方向

【讨论】:

  • 我有类似的问题,这条线对我不起作用
  • @CanberkÖzçelik 自从我查看这段代码以来已经有一段时间了,从那时起,已经发布了 2 个新版本的 Android。所以从那以后有些事情可能会发生变化。
  • 是的,但是如果有人遇到类似的情况没有解决,我的问题就在这里:stackoverflow.com/q/42597256/4432872
  • 我遇到了同样的问题,但使用“AppBarLayout”,经过 5 个多小时寻找解决方案,这个答案救了我。如果上面的那个不起作用试试这个android:windowSoftInputMode="adjustNothing|adjustPan"
  • 如果要调整大小应该怎么做?
【解决方案2】:

尝试将ScrollView 更改为androidx.core.widget.NestedScrollView

这帮助我解决了问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多