android - KOTLIN 在键盘显示时调整片段滚动视图
问题描述
我在滚动视图中有一个表单,需要垂直滚动以在显示键盘时显示表单的其余部分。
我已将此添加到 manifest.xml
android:windowSoftInputMode="stateVisible|adjustResize">
片段.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBlack"
tools:context=".ui.main.ConnectFragment">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:isScrollContainer="false"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical">
//My form
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
片段.kt
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
navController = Navigation.findNavController(view)
我需要在 onViewCreated 中添加一些东西吗?
解决方案
我唯一确定的是你的表单应该在scrollView之外。
它里面的所有东西都会在滚动时做出反应,所以当键盘打开时不会向上移动
推荐阅读
- r - 在 R 中使用平衡设计分析重复测量
- docker - 无法从容器外部访问 Angular
- docker - 使用 Docker 映射 Compute Engine 中的端口
- c - C - 指向结构的指针 - 分段错误
- handlebars.js - handlebars.js - 遍历 json 数组以确定是否应选中复选框
- c# - Web API 2 中的依赖注入服务授权
- c# - MVC ActionResult 模型似乎正在使用缓存视图
- typescript - 将字符串转换为 NSData 并将 NSData 转换回字符串
- c# - C# - 循环并获取具有相同名称的 XML 值的值
- tensorflow - CuDNN——状态未初始化(Keras/TensorFlow + Nvidia P100 + Linux)