android APP登陆页面适配的实现
更新时间:2018年09月06日 08:19:09 作者:FullScreenDev
这篇文章主要介绍了android APP登陆页面适配的实现,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
本文介绍了android APP登陆页面适配的实现,分享给大家,具体如下:
先看效果图。

登陆首页效果图
原理
为RootView增加监听事件,然后进行滚动
至于该滚动多少,这是需要自己慢慢进行计算。
xml
<LinearLayout
android:id="@+id/llLogin"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">
<!--你的布局-->
</LinearLayout>
代码
/**
* 1、大于屏幕整体高度的1/3:键盘显示 获取Scroll的窗体坐标
* 算出main需要滚动的高度,使scroll显示。
* 2、小于屏幕整体高度的1/3:键盘隐藏
*
* @param rootView 根布局
*/
private fun addLayoutListener(rootView: View) {
rootView.viewTreeObserver.addOnGlobalLayoutListener {
val rect = Rect()
rootView.getWindowVisibleDisplayFrame(rect)
val screenHeight = rootView.rootView.height
val mainInvisibleHeight = rootView.rootView.height - rect.bottom
if (mainInvisibleHeight > screenHeight / 4) {
rootView.scrollTo(0, DensityUtils.dp2px(mActivity, 200f/*需要滚动到图片目标高度*/))
} else {
rootView.scrollTo(0, 0)
}
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
Android EditText随输入法一起移动并悬浮在输入法之上的示例代码
这篇文章主要介绍了Android EditText随输入法一起移动并悬浮在输入法之上,本文通过示例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2020-06-06


最新评论