Loading [MathJax]/jax/output/CommonHTML/config.js
社区首页 >问答首页 >为什么当使用WindowCompat.setDecorFitsSystemWindows(window,false时滚动不能正常工作)?

为什么当使用WindowCompat.setDecorFitsSystemWindows(window,false时滚动不能正常工作)?
EN

Stack Overflow用户
提问于 2022-06-28 07:10:26
回答 1查看 157关注 0票数 0

看上去就像当我加上

代码语言:javascript
代码运行次数:0
复制
WindowCompat.setDecorFitsSystemWindows(window, false)

对于我的Android应用程序来说,当键盘打开时,滚动屏幕上的内容就会被破坏。它不允许您滚动到屏幕上的最后一项。这是我正在使用的代码。

代码语言:javascript
代码运行次数:0
复制
package com.example.myapplication

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.WindowCompat
import com.example.myapplication.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {

    private lateinit var binding: ActivityMainBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        WindowCompat.setDecorFitsSystemWindows(window, false)
        super.onCreate(savedInstanceState)

        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)

    }

}
代码语言:javascript
代码运行次数:0
复制
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/containerOfContainers"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clipChildren="false"
        android:clipToPadding="false"
        android:orientation="vertical">

        <TextView
            android:id="@+id/titleText"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:gravity="center_horizontal"
            android:text="Title"
            android:textSize="40sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            tools:layout_constraintTop_creator="1"
            tools:layout_editor_absoluteX="@dimen/spark_gap_tiny">

            <requestFocus />
        </TextView>

        <EditText
            android:id="@+id/first"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:paddingTop="150dp"
            android:text="1"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/titleText" />


        <EditText
            android:id="@+id/second"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:paddingTop="150dp"
            android:text="2"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/first" />

        <EditText
            android:id="@+id/third"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:paddingTop="150dp"
            android:text="3"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/second" />

        <EditText
            android:id="@+id/fourth"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:paddingTop="150dp"
            android:text="4"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/third" />

        <EditText
            android:id="@+id/fifth"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:paddingTop="150dp"
            android:text="5"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/fourth" />

        <EditText
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:paddingTop="150dp"
            android:text="6"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/fifth" />
    </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
代码语言:javascript
代码运行次数:0
复制
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.myapplication">

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.MyApplication"
        tools:targetApi="31">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:label="@string/app_name"
            android:theme="@style/Theme.MyApplication">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

正确(当键盘打开时,我可以一直滚动到6)

错误(我只能在打开键盘时滚动到4)

是什么导致了这一切?这似乎是一个非常简单的用例。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-06-28 08:10:02

弄明白了。我需要在它们改变的时候更新它们。见代码。

代码语言:javascript
代码运行次数:0
复制
package com.example.myapplication

import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.view.WindowInsets
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.WindowCompat
import androidx.core.view.updateLayoutParams
import androidx.core.view.updateMargins
import com.example.myapplication.databinding.ActivityMainBinding


class MainActivity : AppCompatActivity() {

    private lateinit var binding: ActivityMainBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        WindowCompat.setDecorFitsSystemWindows(window, false)
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)


        binding.root.setOnApplyWindowInsetsListener { _, _ ->
            applyKeyboardInsets(binding.root)
        }

    }


    private fun applyKeyboardInsets(root: View): WindowInsets {

        val insets = root.rootWindowInsets.getInsets(WindowInsets.Type.ime())
        root.updateLayoutParams<ViewGroup.MarginLayoutParams> {
            updateMargins(insets.left, insets.top, insets.right, insets.bottom)
        }
        return WindowInsets.Builder()
            .setInsets(WindowInsets.Type.ime(), insets)
            .build()
    }

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72788997

复制
相关文章
Taro中如何将store加载到项目中
上面文章我们了解了如何创建store,最后导出时,在函数内部创建了store,所以导出时,函数需要调用,然后通过provicer组件将其注入到项目中。
挥刀北上
2022/05/11
7650
Taro中如何将store加载到项目中
用PHP将图片以流的形式加载到image标签中
  很多情况下,如果为了网站资源案例考虑,我们就不能直接暴露资源的地址到页面中去,以防被人用工具去扫描盗用资源文件下的文件,在这里我们就可以考虑以前端页面请求后端程序,后端程序加以验证之后,以流的方式将资源输出,这样就会安全多了。
Sindsun
2019/12/06
1.7K0
BufferedImage与byte[]互转
在传输中,图片是不能直接传的,因此需要把图片变为字节数组,然后传输比较方便;只需要一般输出流的write方法即可;
bear_fish
2018/09/19
2.2K0
Java BufferedImage的基本用法
1:读取本地图片: File file = new File(”001.jpg“);//本地图片 BufferedImage image=(BufferedImage)ImageIO.read(file); 2:读取一张网上图片: URL url= new URL(”http://*******“);//url 为图片的URL 地址 BufferedImage image=(BufferedImage)ImageIO.read(url); 3:
用户5927264
2019/08/01
8.5K0
如何将HDFS文件系统挂载到Linux本地文件系统
Hadoop支持通过NFSv3挂载HDFS文件系统到本地目录,允许用户像访问本地文件系统一样访问HDFS,对于普通用户来说大大的简化了HDFS的使用。该功能通过引入NFS Gateway服务实现,将NFS协议转换为HDFS访问协议。本篇文章主要讲述如何将HDFS文件系统挂载到Linux本地。
Fayson
2018/03/29
9K0
如何将HDFS文件系统挂载到Linux本地文件系统
如何将类序列化并直接存储入数据库
本文将从这两个格式器入手,先向大家介绍分别用它们如何实现序列化和反序列化,然后比较两种格式器的不同点。接着我会向大家介绍实现序列化对对象类型的一些要求,同时还要向大家介绍两种不同的序列化方式:基本序列化(Basic Serialization)和自定义序列化(Custom Serialization)。最后,我还会给大家介绍一个实例程序以加深大家对序列化机制的理解程度。
全栈程序员站长
2022/07/19
2.3K0
如何将类序列化并直接存储入数据库
React中的-- 数据流
简介 React的组件简单理解起来其实就是一个函数,这个函数会接收props和state作为参数,然后进行相应的逻辑处理,最终返回该组件的虚拟DOM展现。在React中数据流向是单向的,由父节点流向子节点,如果父节点的props发生了改变,那么React会递归遍历整个组件树,重新渲染所有使用该属性的子组件。那么props和state究竟是什么?它们在组件中起到了什么作用?它们之间又有什么区别和联系呢?接下来我们详细看一下。 Props props其实就是properties的缩写,可以理解为组件的属性,你可
前朝楚水
2018/04/03
1.3K0
Sqlserver远程查询数据下载到本地
sqlcmd -S 本地数据库连接地址 -U 本地用户名 -P 本地密码 -i 执行存储过程文件
十分钟空间
2022/08/17
5820
BufferedImage类、Image类、Graphics类
Image是一个抽象类,BufferedImage是其实现类,是一个带缓冲区图像类,主要作用是将一幅图片加载到内存中(BufferedImage生成的图片在内存里有一个图像缓冲区,利用这个缓冲区我们可以很方便地操作这个图片),提供获得绘图对象、图像缩放、选择图像平滑度等功能,通常用来做图片大小变换、图片变灰、设置透明不透明等。
Twcat_tree
2022/11/30
1.1K0
使用 jsMpeg + webscoket 低延迟播放直接流
在网校教学场景中,从主讲端推流,到视频CND节点分发,最后到用户侧设备播放,这 3 个过程,哪一个是最耗时的?直播延迟,主要延在了哪一步?第 2 步。
LIYI
2020/02/11
3K0
使用 jsMpeg + webscoket 低延迟播放直接流
如何将SAP归档数据合并到数据湖中
SAP系统已经存在了几十年,与大多数本地(Hadoop)或基于云的(Google, Azure, AWS)数据湖不同。这就是为什么经常要存档大量SAP历史数据的原因。这带来了一个挑战——历史SAP归档解决方案以压缩格式将数据存储在基于文件的存储中,很难将这些数据集成到企业数据湖中,更不用说运行实时分析、机器学习算法或从中创造商业价值。
SNP数据迁移
2023/02/14
8930
如何将SAP归档数据合并到数据湖中
数据流中的中位数
如何得到一个数据流中的中位数?如果从数据流中读出奇数个数值,那么中位数就是所有数值排序之后位于中间的数值。如果从数据流中读出偶数个数值,那么中位数就是所有数值排序之后中间两个数的平均值。
MickyInvQ
2021/12/07
3730
数据流中的中位数
如何得到一个数据流中的中位数?如果从数据流中读出奇数个数值,那么中位数就是所有数值排序之后位于中间的数值。如果从数据流中读出偶数个数值,那么中位数就是所有数值排序之后中间两个数的平均值。我们使用Insert()方法读取数据流,使用GetMedian()方法获取当前读取数据的中位数。
名字是乱打的
2022/05/13
4470
[剑指offer] 数据流中的中位数
如何得到一个数据流中的中位数?如果从数据流中读出奇数个数值,那么中位数就是所有数值排序之后位于中间的数值。如果从数据流中读出偶数个数值,那么中位数就是所有数值排序之后中间两个数的平均值。我们使用Insert()方法读取数据流,使用GetMedian()方法获取当前读取数据的中位数。
尾尾部落
2018/09/04
8080
java中的io流知识总结_java数据流
无意中发现了一个巨牛的人工智能教程,忍不住分享一下给大家。教程不仅是零基础,通俗易懂,而且非常风趣幽默,像看小说一样!觉得太牛了,所以分享给大家。点 这里 可以跳转到教程。
全栈程序员站长
2022/11/01
5550
java中的io流知识总结_java数据流
在Pytorch中构建流数据集
在处理监督机器学习任务时,最重要的东西是数据——而且是大量的数据。当面对少量数据时,特别是需要深度神经网络的任务时,该怎么办?如何创建一个快速高效的数据管道来生成更多的数据,从而在不花费数百美元在昂贵
deephub
2020/12/11
1.2K0
在Pytorch中构建流数据集
API场景中的数据流
原文地址:https://dzone.com/articles/data-streaming-in-the-api-landscape
大数据弄潮儿
2018/05/30
1.5K0
dcoker安装nginx 并将数据挂载到本地
1、使用docker ps 查看正在运行的容器\或者使用docker ps -a 查看所有容器 获得容器的id
烤红薯
2021/12/23
9800
dcoker安装nginx 并将数据挂载到本地
java BufferedImage Graphics 绘制验证码
在爬虫横行的年代,该增加验证码来限制它的发育了! package test; import javax.imageio.ImageIO; import java.awt.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.sql.SQLException; import java.util.ArrayList; import java.util.Random
IT架构圈
2018/06/01
1.3K0
GDS中如何加logo
好,言归正传,在GDS中打上自己的logo是一件很cool的事,而且有时候也是很必要的。
白山头
2020/06/29
1.1K0

相似问题

从ConcurrentDictionary中删除项

22

基于条件键从ConcurrentDictionary中删除多个项

43

如何在最终完成ConcurrentDictionary后从ContinueWith中删除项

14

从ConcurrentDictionary中删除多个元素

11

嵌套的ConcurrentDictionary

14
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档