Android笔记之输入法挡住控件解决

1、在AndroidManifest.xml的Activity设置属性:android:windowSoftInputMode = "adjustResize" ,软键盘弹出时,要对主窗口布局重新进行布局,并调用onSizeChanged方法,切记一点当我们设置为“adjustResize”时,我们的界面 不要设置为全屏模式,否则设置了这个属性也不会有什么效果。

当我们设置 android: windowSoftInputMode = "adjustPan",主窗口就不会调用onSizeChanged方法,界面的一部分就会被软键盘覆盖住,就不会被挤到软键盘之上了

2,将布局改成ScrollView

<?xml version="1.0" encoding="utf-8"?>
<ScrollView    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
         >
<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    
    <com.example.edit.MyEditText
        android:id="@+id/tv_state"
        android:layout_width="match_parent"
        android:layout_height="278dp"
        android:background="#cccccc"
        android:focusable="true"
        android:gravity="top"
        android:hint="@string/note"
        android:textSize="25dp" />
       <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="测试4" />
</LinearLayout>
</ScrollView>
原文地址:https://www.cnblogs.com/xingyyy/p/3278042.html