输入法出现时,中间固定,底部上移的代码

  读了一篇Android实现弹出输入法时,顶部固定,中间部分上移的效果文章之后,大致方法已经知道,可是怎么调都调不对,因此笔者试了各种方法,最后才发现由于一个小细节才没有局部上移的效果。

  具体步骤如下:

    (1)在AndroidManifest.xml中配置的activity标签里添加android:windowSoftInputMode="stateAlwaysHidden|adjustResize"属性,stateAlwaysHidden可以不加,adjustResize一定要加。

    (2)如果activity是全屏,请去掉全屏属性,否则无法有此效果。笔者就是在这一步中招了,由于个人习惯,喜欢设置全屏的activity,所以导致无法完成局部上移的效果。

    (3)最后,布局文件如下:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
     xmlns:android="http://schemas.android.com/apk/res/android">

    <ScrollView
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:fillViewport="true">
        <!-- 固定布局 fillViewport表示子布局填充满-->

     <!-- 该scrollview的子布局期盼是使用具体高度,尽量不用matchparent属性->

</ScrollView> <RelativeLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_alignParentBottom="true"> <EditText android:id="@+id/edittext" android:layout_width="match_parent" android:layout_height="30dp" android:layout_alignParentBottom="true" /> </RelativeLayout> </RelativeLayout>
原文地址:https://www.cnblogs.com/jlyg/p/6594768.html