Android将文本框移动到软键盘上的屏幕顶部

时间:2014-06-16 09:52:27

标签: android android-layout resize android-softkeyboard

我知道在Android中,当软键盘可见且应用程序未处于全屏模式时,Android会重新定位并推送上面的布局,以便文本框不会隐藏在键盘后面。为此,我们将以下内容添加到清单

    android:windowSoftInputMode="adjustResize|stateHidden"

此外,视图需要可滚动。我的布局如下所示。所有这一切都很好,文本框向上移动,但我需要将其一直向上移动到屏幕顶部或至少在键盘上方。我有一个autocompletetextview,当我输入时显示一个建议列表,但是由于键盘占用屏幕的一半而文本框在键盘上方移动,建议列表在我键入的文本框上方悬停,我需要文本框移动到屏幕顶部附近,以便建议列表显示在autocompletetextview下面而不是它上面。可以吗? (通过代码或一些配置?)

    <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_below="@+id/navbar"
    android:layout_above="@+id/navbar2">

    <ScrollView
        android:id="@+id/masterContainerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="#E9E9E9"
        android:isScrollContainer="true"
        android:scrollbars="none" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_margin="30dp"
            android:gravity="center"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/apptitle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:gravity="center"
                android:layout_weight="0.11"
                android:fontFamily="Roboto"
                android:text="Please Enter The Details Below"
                android:textColor="#444444"
                android:textSize="20sp" />

            <Spinner
                android:id="@+id/spinner"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="30dp"
                android:prompt="@string/plspinner" />

            <AutoCompleteTextView
                android:id="@+id/autosuggestProducts"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="30dp"
                android:ems="10"
                android:textColor="#444444" >
            </AutoCompleteTextView>

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="30dp"
                android:gravity="center"
                android:onClick="goToResults"
                android:text="@string/search" />
        </LinearLayout>
    </ScrollView>
</LinearLayout>

0 个答案:

没有答案
相关问题