我是靠谱客的博主 怕孤单睫毛膏,最近开发中收集的这篇文章主要介绍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 APP登陆页面适配的实现的全部内容,希望文章能够帮你解决android APP登陆页面适配的实现所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(162)

评论列表共有 0 条评论

立即
投稿
返回
顶部