本文介紹了android APP登陸頁面適配的實(shí)現(xiàn),分享給大家,具體如下:
先看效果圖。
登陸首頁效果圖
原理
為RootView增加監(jiān)聽事件,然后進(jìn)行滾動(dòng)
至于該滾動(dòng)多少,這是需要自己慢慢進(jìn)行計(jì)算。
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的窗體坐標(biāo) * 算出main需要滾動(dòng)的高度,使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/*需要滾動(dòng)到圖片目標(biāo)高度*/)) } else { rootView.scrollTo(0, 0) } }}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
網(wǎng)友關(guān)注