1、期望的效果:
- 输入法弹起时,背景图不要向上移动或压缩
- 输入法弹起时,不要遮挡输入框,输入框可以向上移动;
2、实现方式:
1、在AndroidManifest.xml 中设置对应Activity的输入法模式:
android:windowSoftInputMode="adjustResize|stateHidden"
2、页面的背景不要设置在xml布局中,通过代码设置背景:
// 设置背景图片
getWindow().setBackgroundDrawableResource(R.drawable.loginbg);
3、使用ScrollView嵌套需要滚动的布局
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical">
// 布局
</LinearLayout>
</ScrollView>
本文介绍了在Android应用开发中如何解决软键盘弹出时页面布局错位的问题。主要通过三种方式实现:一是在AndroidManifest.xml中配置Activity的输入法模式;二是避免在XML布局文件中设置页面背景,改为通过代码设置;三是使用ScrollView包裹需要滚动的布局。
338

被折叠的 条评论
为什么被折叠?



