【问题标题】:Android - adjust scrollview when keyboard is up for android 5.0 (lollipop)Android - 当键盘为 android 5.0 (棒棒糖) 启动时调整滚动视图
【发布时间】:2015-01-25 20:16:45
【问题描述】:

我在使用 android lollipop 时遇到问题,当软键盘出现时屏幕没有调整大小。

这是我所做的一项活动中的清单介绍示例:

android:windowSoftInputMode="stateAlwaysHidden|adjustResize" 

是否添加了一些新的东西,我们必须考虑到 android 5.0 ?滚动视图在 android 上运行良好

【问题讨论】:

    标签: android android-layout android-manifest android-softkeyboard android-scrollview


    【解决方案1】:

    问题是它不适用于半透明状态栏,我必须设置

     android:fitsSystemWindows="true"
    

    在我的主布局中

    【讨论】:

    • 你救了我!谢谢。我一直在寻找这个答案 2 天。
    【解决方案2】:

    对于即使在 ScrollView 中使用 android:fitsSystemWindows="true" 仍然存在此问题的人。

    我找到了几种解决方法:

    1. 以root身份使用fragment.xml布局RelativeLayour并将android:fitsSystemWindows="true"放在里面。 ScrollView 用作RelativeLayour 的子项。
    <RelativeLayout android:fitsSystemWindows="true">
      <ScrollView/>
    </RelativeLayout>
    
    1. 使用 NestedScrollView 而不是 ScrollView。

    这两个选项都应与android:windowSoftInputMode="adjustResize" 一起使用,并且可以在带有&lt;item name="android:windowTranslucentStatus"&gt;true&lt;/item&gt; 标志的Android 5 上使用。 `

    【讨论】:

    • 我不确定如何实现。你能再详细一点吗?谢谢。
    【解决方案3】:

    我尝试过的任何方法都没有奏效,并且我已经经历了不同清单设置等的每一个可能的组合,但无济于事。

    它有点老套,但对我来说效果很好:

    ((RelativeLayout) findViewById(R.id.rootLayout)).addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
                @Override
                public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                    scrollToLatest(); // Do your scrolling!
                }
            });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-07
      • 1970-01-01
      • 2014-12-19
      • 1970-01-01
      • 2015-01-18
      相关资源
      最近更新 更多