之前见到需要小伙伴们搜寻这个问题,有的是在配置文件中设置: 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
5135

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



