[英]How to move up the whole layout when keyboard shown?
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<LinearLayout
android:layout_gravity="bottom"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</FrameLayout>
在清單中:
android:windowSoftInputMode="adjustPan"
初始行為:
目前的行為:
期望的行為:
如何實現所需的布局行為? adjustResize不適合,因為此選項調整布局大小。
謝謝你的回答!
你可能想看看這個答案 。 一個建議:
將Window SoftInput Mode屬性設置為adjustPan和adjustResize
<activity android:windowSoftInputMode="adjustPan|adjustResize"> </activity>
獲得該結果的唯一方法是調整大小布局。 使用android:windowSoftInputMode =“adjustResize”
在你的清單中嘗試這個:
android:windowSoftInputMode="adjustResize|stateUnchanged"
檢查包含EditText和Button的布局是否為RelativeLayout。
嘗試改變FrameLayout
到RelativeLayout
與alignParentBottom="true"
在你的財產LinearLayout
:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<LinearLayout
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
您將無法使用adjustPan
實現這adjustPan
,因為來自官方指南
活動的主窗口未調整大小以便為軟鍵盤騰出空間。 相反,窗口的內容會自動平移,以便鍵盤不會遮擋當前焦點,用戶可以隨時看到他們正在鍵入的內容。 這通常比調整大小更不合適,因為用戶可能需要關閉軟鍵盤以獲得窗口的模糊部分並與其交互。
您的Button
位於當前焦點EditText
下方
通過從活動和android:windowSoftInputMode清除下面的行,我得到整個布局滾動,這是以前隱藏的
this.getWindow()。setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
請檢查此輸出視頻鏈接: https : //mega.nz/#!TpRCWZjY!TqDzv0Yn3Q24PR1JAdH8kRVeDf2iSa1LQbNBgF0SVHk
我不相信有一個簡單的方法可以做到這一點。 至少不像設置標志那么簡單。 我有類似的情況,希望鍵盤上升到遠低於所選EditText的視圖級別。 我最終使用了這個答案: 如何檢查Android中軟件鍵盤的可見性?
鍵盤變為可見時手動調整視圖大小。
只需在活動中使用此屬性即可
android:windowSoftInputMode="adjustPan"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.