Android在软键盘上将文本框移动到屏幕顶部
我知道,在安卓系统中,当软键盘可见,且应用程序未处于全屏模式时,安卓系统会重新定位并推动上面的布局,这样就不会在键盘后面隐藏文本框。为此,我们在清单中添加以下内容Android在软键盘上将文本框移动到屏幕顶部,android,android-layout,resize,android-softkeyboard,Android,Android Layout,Resize,Android Softkeyboard,我知道,在安卓系统中,当软键盘可见,且应用程序未处于全屏模式时,安卓系统会重新定位并推动上面的布局,这样就不会在键盘后面隐藏文本框。为此,我们在清单中添加以下内容 android:windowSoftInputMode="adjustResize|stateHidden" 此外,视图还需要可滚动。我的布局如下所示。所有这些都很好,文本框向上移动,但我需要将它一直向上移动到屏幕顶部,或者至少在键盘上方。我有一个autocompletetextview,当我打字时它会显示一个建议列表,但是
android:windowSoftInputMode="adjustResize|stateHidden"
此外,视图还需要可滚动。我的布局如下所示。所有这些都很好,文本框向上移动,但我需要将它一直向上移动到屏幕顶部,或者至少在键盘上方。我有一个autocompletetextview,当我打字时它会显示一个建议列表,但是由于键盘占据了屏幕的一半,文本框刚好在键盘上方移动,建议列表在我打字时会悬浮在文本框上方,我需要文本框在上面移动,靠近屏幕顶部,以便建议列表显示在autocompletetextview下方,而不是其上方。能做到吗?(通过代码或某些配置?)
仅尝试使用android:WindowsOfInputMode=“adjustResize”。您已经为布局留下了页边距。可能是因为textview没有移动到顶部。我的清单中已经有了上面的配置。你能解释一下我为版面留了空白是什么意思吗?试着从LinearLayout中删除android:layout\u margin=“30dp”
,然后检查。没有任何区别。试过了。
<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>