简体   繁体   English

Android 键盘滑动动画

[英]Android keyboard slide animation

I have little (read: no) experience with animations in Android, but wanted to implement an animation for when the keyboard appears.我对 Android 中的动画几乎没有(阅读:没有)经验,但想在键盘出现时实现动画。 Effectively, it would appear that the entire activity was sliding upwards (like the keyboard was below the activity and pushed it upwards), as opposed to only moving up so far as the selected EditText .实际上,看起来整个 Activity 都在向上滑动(就像键盘在 Activity 下方并将其向上推一样),而不是仅向上移动到选定的EditText

Does anyone know how to do this?有谁知道如何做到这一点?

In the latest version of Android OS (Android version 11), they added new set of APIs let you synchronize your app's content with the IME (input method editor, aka soft keyboard) and system bars as they animate on and offscreen, making it much easier to create natural, intuitive and jank-free IME transitions.在最新版本的 Android 操作系统(Android 版本 11)中,他们添加了一组新的 API,让您可以在屏幕上和屏幕外设置动画时将应用程序的内容与 IME(输入法编辑器,又名软键盘)和系统栏同步更容易创建自然、直观和无卡顿的 IME 转换。

WindowInsetsAnimation.Callback WindowInsetsAnimation.Callback

For frame-perfect transitions, a new insets animation listener notifies apps of per-frame changes to insets while the system bars or the IME animate.对于完美的帧过渡,新的插入动画侦听器会在系统栏或 IME 动画时通知应用程序每帧对插入的更改。

在此处输入图片说明

WindowInsetsAnimationController WindowInsetsAnimationController

Apps can take control of the IME and system bar transitions through the WindowInsetsAnimationController API.应用程序可以通过WindowInsetsAnimationController API 控制 IME 和系统栏转换。

在此处输入图片说明

An app receives no notification of when a keyboard appears, and the android framework itself is responsible for either sliding the app or laying it out again.应用程序不会收到键盘出现的通知,Android 框架本身负责滑动应用程序或重新布局。 So customization isn't really possible.所以定制是不可能的。 Which is probably a good thing- a keyboard is a separate app, and having written one I wouldn't want to even try to write the keyboard half of such an animation, we'd never get it to look right with all the various ways the app could do it.这可能是一件好事 - 键盘是一个单独的应用程序,并且编写了一个我什至不想尝试编写这样一个动画的键盘一半,我们永远不会让它以各种方式看起来正确该应用程序可以做到。

The closest you'll get is to specify the fields to pan rather than resize when the keyboard is opened.最接近的是指定要平移的字段而不是在打开键盘时调整大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM