软件编程
位置:首页>> 软件编程>> Android编程>> android APP登陆页面适配的实现

android APP登陆页面适配的实现

作者:FullScreenDev  发布时间:2022-08-27 17:55:57 

标签:android,APP,登陆,适配

本文介绍了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)
   }
 }
}

来源:https://www.jianshu.com/p/d993a1e71339

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com