3

android:windowSoftInputMode="adjustPan"在我的manifest.xml. 它让我的工作做得很好,但它有些迟钝。当我关注一个EditText视图时,比如在屏幕的下半部分,标题栏也会随着活动的内容滚动。

图片在这里

我想要的只是在滚动内容时冻结/浮动标题栏。像这样:

图片在这里

不,我不想使用adjustResize它在彼此之上重叠视图

非常感谢任何帮助,长期以来一直在寻找答案。

4

2 回答 2

0

找到了!

只需将布局 xml 文件中的根视图更改为 a 即可ScrollView

我什至不需要指定android:windowSoftInputMode

当然,我必须将其他所有内容都放在一个布局中作为ScrollView

编辑

您的 .xml 文件应如下所示:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    ... >
    <LinearLayout>    // could be any other layout but linear works well here
        //insert all other views of the activity here
    </LinearLayout>
</ScrollView>
于 2014-03-24T05:29:30.087 回答
-1

Ace 提出的答案基本上就是所需要的。我的回答只是为了让事情更清楚一些。

您需要做两件事。首先在 Manifest 中设置以下活动。android:windowSoftInputMode="adjustResize"

然后,在 Activity 的布局中,您需要在 Toolbar/Title Bar 下方设置一个 ScrollView,如下面的代码所示。

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

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_height="?attr/actionBarSize"
        .../>

    <ScrollView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ...>

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                ...>
           </RelativeLayout>

    </ScrollView>
</RelativeLayout>

据我了解,这是它的工作原理。当您在设备上打开软键盘时,它将“调整大小”活动的布局。由于布局位于 ScrollView 中,因此这是调整大小并变小的部分。因此,工具栏/标题栏将保持原位,并且在显示键盘时 ScrollView 中的布局将是可滚动的。

于 2016-05-04T15:11:32.257 回答