代码之家  ›  专栏  ›  技术社区  ›  Ace

android:使用adjustPan,不滚动标题栏

  •  4
  • Ace  · 技术社区  · 11 年前

    我正在使用 android:windowSoftInputMode="adjustPan" 在我的 manifest.xml . 我的工作做得很好,但这有点弱智。 当我聚焦 EditText 视图,也就是说,在屏幕的下半部分,标题栏也与活动内容一起滚动。

    image here

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

    image here

    不,我不想用 adjustResize 它将视图重叠在一起

    我们非常感谢您的帮助,我们一直在寻找答案。

    2 回复  |  直到 4 年前
        1
  •  0
  •   Ace    8 年前

    找到了!

    只需将布局xml文件中的根视图更改为 ScrollView 完成工作。

    我甚至不需要说明 android:windowSoftInputMode

    当然,作为 卷轴视图

    编辑

    .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>
    
        2
  •  -1
  •   James Warner    8 年前

    艾斯提出的答案基本上是需要的。我的回答只是为了让事情更清楚一点。

    有两件事你需要做。首先在清单中设置以下活动。 android:windowSoftInputMode="adjustResize"

    然后,在活动的布局中,您需要在工具栏/标题栏下设置一个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中的布局将可滚动。