服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - Android - android APP登陆页面适配的实现

android APP登陆页面适配的实现

2022-07-31 12:12FullScreenDev Android

这篇文章主要介绍了android APP登陆页面适配的实现,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

本文介绍了android APP登陆页面适配的实现,分享给大家,具体如下:

先看效果图。

android APP登陆页面适配的实现

登陆首页效果图

原理

为RootView增加监听事件,然后进行滚动

至于该滚动多少,这是需要自己慢慢进行计算。

xml

?
1
2
3
4
5
6
7
8
<LinearLayout
    android:id="@+id/llLogin"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:orientation="vertical">
    <!--你的布局-->
</LinearLayout>

代码

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
 * 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

延伸 · 阅读

精彩推荐