本文介绍了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)
}
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持华域联盟。
声明:本站(华域联盟www.cnhackhy.com)所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

评论(0)