android-studio - 视图可见后滚动
问题描述
在单击按钮后视图变得可见后,我试图滚动到我的滚动视图的底部。问题是在视图实际可见之前应用了 scrollTo 函数。我知道这一点,因为当按钮被按下两次时,它会在第二次点击时滚动到底部。那么,有没有办法在视图变得可见后滚动?
button.setOnClickListener(v -> {
constraintLayout.setVisibility(View.VISIBLE);
scrollView.smoothScrollTo(0, constraintLayout.getBottom());
}
解决方案
button.setOnClickListener(v -> {
constraintLayout.setVisibility(View.VISIBLE);
Handler handler = new Handler();
handler.postDelayed(() -> {
scrollView.smoothScrollTo(0, constraintLayout.getBottom());
}, 100);
}
我刚刚发现这是可行的,但我希望不要使用延迟。
推荐阅读
- c# - 何时以及为何访问 CoreWindow.ActivationMode 会引发 InvalidCastException?
- docker - docker 容器中的 Sonarcube 凭据
- gulp - 带有 at-signs/asperands (@) 的 Pug 标签名称
- python - 在 python 3.7 中安装熊猫
- function - MASM 如何进行所需的函数调用
- php - 无法使用 PHP 从使用 Cloud Firestore 的嵌套集合中获取文档
- jquery - 如何在数字类型的输入中更改数字时触发函数?
- jquery - 尝试使用 jquery ajax 传递对象列表
- llvm - 从 LLVM callInst 临时提取
- r - 当出现次数未知时,如何用反向引用替换?