android软键盘出现时会破坏布局

前端之家收集整理的这篇文章主要介绍了android软键盘出现时会破坏布局前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这是一个布局:
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent" >
  5.  
  6. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  7. xmlns:tools="http://schemas.android.com/tools"
  8. android:orientation="vertical"
  9. android:layout_width="match_parent"
  10. android:layout_height="match_parent" >
  11.  
  12. <FrameLayout
  13. android:layout_width="match_parent"
  14. android:layout_height="0px"
  15. android:layout_weight="1" />
  16.  
  17. <FrameLayout
  18. android:background="#0000ff"
  19. android:layout_width="match_parent"
  20. android:layout_height="0px"
  21. android:layout_weight="1" />
  22.  
  23. <FrameLayout
  24. android:layout_width="match_parent"
  25. android:layout_height="0px"
  26. android:layout_weight="1" />
  27.  
  28. </LinearLayout>
  29.  
  30. <EditText
  31. android:layout_width="match_parent"
  32. android:layout_height="wrap_content"
  33. android:layout_alignParentBottom="true" />
  34.  
  35. </RelativeLayout>

当触摸EditText并出现软键盘时,我希望蓝条保持不变.即我希望保留它的大小和位置.我在AndroidManifest中为我的activity的参数android:windowSoftInputMode尝试了所有四个可能的值.总是我的蓝色条在软键盘上移动或缩小:

android:windowSoftInputMode =“adjustUnspecified”或默认情况下:

android:windowSoftInputMode =“adjustPan”或android:windowSoftInputMode =“adjustNothing”:

机器人:windowSoftInputMode = “adjustResize”:

当软键出现时,它是否可以保持相同的大小和位置?

解决方法

由于输入进入你的EditText,它总是会移动一些东西.

考虑使用两种布局,一种用于键盘关闭时,一种用于键盘启动时.

使用ViewSwitcher可能会有所帮助.

猜你在找的Android相关文章