解决登录页面软键盘弹出所有布局集体上移,不错乱。亲测可行。

之前见到需要小伙伴们搜寻这个问题,有的是在配置文件中设置: windowSoftInputMode 属性,这种可以实现一些简单需求,比如软键盘的默认状态.(具体属性方法自己去实现会深刻点)这种设置属性后也会造成布局被顶起之后的 布局错乱。而今天给大家说的是在布局文件中,根目录为scrollView 的方式,之前也看到有人提过这个方法 ,有的说是将需要顶起的布局 包括进去,但这种实现不了所有布局的全部上移展示(获取焦点的地方以及上部布局可以显示出来).



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:fitsSystemWindows="true">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </ScrollView>
    <LinearLayout
        android:layout_width="match_parent"
        android:orientation="vertical"
        android:layout_centerInParent="true"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:gravity="center">

            <TextView
                android:text="手机验证登录"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="80dp"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:text="手机号码 :" />

                <EditText
                    android:id="@+id/login_phone"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="10dp"
                    android:layout_weight="1"
                    android:maxLength="11"
                    android:background="@null"
                    android:gravity="center_vertical"
                    android:inputType="phone" />

                <TextView
                    android:id="@+id/send_code"
                    android:layout_width="80dp"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:text="发送验证码"
                    android:textColor="#FFC5C5C9" />
            </LinearLayout>

            <View
                android:layout_width="match_parent"
                android:layout_height="1px"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:background="#C8C7CC" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="80dp"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:text="  验证码 :" />

                <EditText
                    android:id="@+id/login_code"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="10dp"
                    android:background="@null"
                    android:gravity="center_vertical"
                    android:inputType="number"
                    android:maxEms="6" />
            </LinearLayout>

            <View
                android:layout_width="match_parent"
                android:layout_height="1px"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:background="#C8C7CC" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:gravity="center">

                <Button
                    android:id="@+id/login"
                    android:layout_width="wrap_content"
                    android:layout_height="50dp"
                    android:background="@null"
                    android:gravity="center"
                    android:text="登录"
                    android:textColor="#409BFF"
                    android:textSize="18sp" />
            </LinearLayout>

        </LinearLayout>

    </LinearLayout>
</RelativeLayout>

附上例子代码。用relativelayout 在底层用scrollview 充满, 在之上我们的布局文件。 这样软键盘弹出的时候  我们所有的布局文件都会集体上移。

 附上 效果图:

     

分享使人快乐。之前看过一位大神的博客,记忆尤甚的一句话: 不要花太多的精力 去为了实现什么样的特效,多去探索一些底层的东西。  。。。 虽然感觉很遥远,但方向不变,我们不变,就走下去。

转载请注明原创地址 : http://blog.csdn.net/qq_34062297/article/details/77697393


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值