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)
        }
    }
}

微信公众号

《APP登陆页面适配》 AndroidRookie

    原文作者:AndroidRookie
    原文地址: https://www.jianshu.com/p/d993a1e71339
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞