软键盘弹出布局上移
来源:互联网 发布:教学质量分析软件 编辑:程序博客网 时间:2024/05/16 07:04
一、摘要
公司登录功能让实现弹出软键盘,布局滑动效果使得将登录按钮顶上去,网上查了很多资料,大部分都是添加adjustPan | stateVisible 的属性,但是问题是我的界面效果没什么效果,它只是弹出到输入框的底部,离想要的效果还有很大差异。也有的网友说直接用LinearLayout 的权重 + ScrollView 来实现,但是效果也是不太理想。
二、功能实现
实现登录页面软键盘顶起功能,主要用了:
1)ScrollView + LinearLayout 权重效果;
2)设置需要顶起的控件,然后计算向上滑动距离。
三、布局
主要实现:使用ScrollView 作为最外层的控件,在布局中使用LinearLayout 的权重效果进行界面的实现
<?xml version="1.0" encoding="utf-8"?><ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/scrollView" android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true"> <RelativeLayout android:id="@+id/rl_login_bg" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/white_ffffff"> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/login_bg" android:fitsSystemWindows="true" android:scaleType="fitCenter"></ImageView> <LinearLayout android:id="@+id/ll_content" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:paddingBottom="45dp" android:paddingTop="80dp"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:scaleType="fitCenter" android:src="@drawable/logo_shb" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="vertical" android:paddingTop="70dp"> <android.support.design.widget.TabLayout android:id="@+id/tl_login_type" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="27dp" android:layout_marginRight="27dp" app:tabGravity="fill" app:tabIndicatorColor="@color/blue_01e2e6" app:tabIndicatorHeight="2dp" app:tabMode="fixed" app:tabSelectedTextColor="@color/blue_01e2e6" app:tabTextAppearance="@style/CustomTabTextAppearanceStyle" app:tabTextColor="@color/gray_666666" app:theme="@style/Widget.Design.TabLayout"> <android.support.design.widget.TabItem android:id="@+id/tabitem_commen" android:layout_width="match_parent" android:layout_height="match_parent" android:fadingEdge="none" android:text="@string/login_convinent" /> <android.support.design.widget.TabItem android:id="@+id/tabitem_convinent" android:layout_width="match_parent" android:layout_height="match_parent" android:fadingEdge="none" android:text="@string/login_commen" /> </android.support.design.widget.TabLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v4.view.ViewPager android:id="@+id/vp_login" android:layout_width="match_parent" android:layout_height="270dp" android:layout_marginTop="20dp"></android.support.v4.view.ViewPager> <LinearLayout android:id="@+id/ll_empty" android:layout_width="match_parent" android:layout_height="0dp" android:layout_marginTop="270dp" android:orientation="horizontal"></LinearLayout> </RelativeLayout> </LinearLayout> </LinearLayout> <LinearLayout android:id="@+id/ll_back" android:layout_width="30dp" android:layout_height="62dp"> <ImageView android:id="@+id/iv_back" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="15dp" android:layout_marginTop="32dp" android:src="@drawable/back_white" /> </LinearLayout> </RelativeLayout></ScrollView>
四、实现软键盘弹出布局的滑动
测量软键盘弹出的时候布局滑动的距离。
LayoutUtil.controlKeyboardLayout(rlLoginBg, llEmpty);
public class LayoutUtil { public static void controlKeyboardLayout(final View root, final View scrollToView) { root.getViewTreeObserver().addOnGlobalLayoutListener( new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { Rect rect = new Rect(); root.getWindowVisibleDisplayFrame(rect); int rootInvisibleHeight = root.getRootView() .getHeight() - rect.bottom; if (rootInvisibleHeight > 100) { int[] location = new int[2]; scrollToView.getLocationInWindow(location); int srollHeight = (location[1] + scrollToView .getHeight()) - rect.bottom; root.scrollTo(0, srollHeight); } else { root.scrollTo(0, 0); } } }); }}
五、总结
目前我的界面软件顶起登录按钮用这种方式实现了,缺少一个点都无法实现,布局顶起的效果是实现了,但是目前我的登录有快捷登录效果,验证码倒计时存在界面闪动问题,目前还在解决中,希望哪位有好的解决方法可以分享下。
阅读全文
0 0
- 软键盘弹出布局上移
- android 软键盘弹出 布局上移动
- Android软键盘弹出,界面布局整体上移
- 软键盘弹出布局与edittext一起上移
- EditText弹出软键盘后布局上移问题
- Android弹出软键盘布局是否上移问题
- 软键盘弹出控件上移
- Android软键盘(二) 软键盘弹出布局上移的问题
- 实现 软键盘弹出,界面整体上移
- android 软键盘弹出,界面上移
- Android软键盘弹出,底部Menu上移
- 软键盘弹出,listview上移的解决方法
- 软键盘弹出,控件上移问题
- 软键盘弹出,整体界面上移
- Android软键盘弹出,界面整体上移
- Android软键盘(四)软件盘弹出布局上移的问题(2)
- 关于Edittext点击弹出软键盘,布局上移标题消失问题,微信聊天界面
- Android 软键盘弹出时布局内指定内容上移实现及问题解决
- Java小知识-判断字符串中有多少中文
- HyperLedger/fabric1.0.0正式版部署
- 我的服务器开发之路-windows计划任务的使用
- Vue自定义指令的使用
- Setup docker on OSX
- 软键盘弹出布局上移
- 利用栈反向打印单链表
- HUST 1010 The Minimum Length(KMP)
- mongodb远程连不上的解决方法
- 前端基本功—js第二天
- Redis常用命令
- Linux系统下安装jdk详细步骤(共两种方法)
- ubuntu 解決搜狗无法输入中文的问题
- ubuntu 16.04下安装使用OpenCV2.4.13