Android软键盘弹出将底部栏顶上去并不会挤压界面

     界面需要,找到了一种不需要去设置android:windowSoftInputMode属性的解决keyboard和layout不适问题

     有关设置android:windowSoftInputMode的资料,可自行百度。

     我的方法就是,将xml文件的根布局设置成ScrollView,将之前的布局嵌套在里面就行了,不需要去设置以上的任何属性

     在中间没有控件显示的地方,使用view设置weight去占位置

    下面给出我的xml布局

    

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    tools:context="com.example.richedit.TestInputMethodActivity" >

    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">
        <LinearLayout 
            android:layout_width="fill_parent"
            android:layout_height="40dp"
            android:background="#332423">
            
        </LinearLayout>
        <View android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"/>
        <EditText 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
        <EditText 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
        <View 
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"/>
        <RelativeLayout 
            android:layout_width="fill_parent"  
            android:layout_height="54dip"  
            android:background="@android:drawable/bottom_bar">
            <Button  
                android:id="@+id/manual_setup"  
                android:text="zuozuo"  
                android:layout_height="wrap_content"  
                android:layout_width="wrap_content"  
                android:minWidth="100dp"  
                android:layout_alignParentLeft="true"  
                android:layout_centerVertical="true" />  
            <Button  
                android:id="@+id/next"  
                android:text="youyou"  
                android:layout_height="wrap_content"  
                android:layout_width="wrap_content"  
                android:minWidth="100dp"  
                android:layout_alignParentRight="true"  
                android:layout_centerVertical="true" />  
        </RelativeLayout>
    </LinearLayout>

</ScrollView>

   这里给出keyb弹出时和没弹出时的效果图,很好的将底部栏顶了上去

  

             

原文地址:https://www.cnblogs.com/robben/p/4832618.html