Android软键盘推视图

时间:2015-12-30 04:59:05

标签: android android-layout view keyboard android-softkeyboard

我正在为Android开发一个软键盘,我遇到了一个我无法解决的问题。问题是,当我打开键盘时,它会错误地移动其他视图(参见图片,我的键盘在左侧)。

This is how my problem looks like

我尝试过在stackoverflow或其他地方找到的多个解决方案,但它们并不适用于我。

我试过了:

android:windowSoftInputMode="adjustResize"
android:windowSoftInputMode="stateHidden|adjustPan"
android:windowSoftInputMode="adjustResize|stateVisible|stateAlwaysHidden"

但它并没有改变你在屏幕截图上看到的行为。

所以,请帮我解决这个问题。

聚苯乙烯。我知道有很多类似的问题,"adjustResize""stateHidden|adjustPan"提供,但它对我不起作用。

P.p.s截图是在android 6.0.1中拍摄的。

感谢。

4 个答案:

答案 0 :(得分:2)

我终于在问题中找到了answer。您需要在扩展InputMethodService的类中使用此代码:

@Override
public void onComputeInsets(InputMethodService.Insets outInsets) {
     super.onComputeInsets(outInsets);
     if (!isFullscreenMode()) {
        outInsets.contentTopInsets = outInsets.visibleTopInsets;
     }
}

答案 1 :(得分:1)

您只需将活动的 windowSoftInputMode 标记切换为" adjustPan "。删除 adjustResize

 <activity
   ...
   android:windowSoftInputMode="adjustPan"> 
   </activity>

答案 2 :(得分:0)

尝试使用scrollView

包装您的布局
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    .
    .
    .
    .
</ScrollView>

答案 3 :(得分:0)

我认为android:windowSoftInputMode可以工作,但是像这样:

android:windowSoftInputMode="adjustNothing"

试试吧。

相关问题