如何让键盘动起来?

发布于 2025-01-16 00:25:36 字数 7091 浏览 2 评论 0原文

我有一个应用程序,我想为键盘设置动画,如下所示:

或者 gif 不起作用,您可以转到 url 并获取 gif。

请忽略第一张图片。我问的是第二个。

我需要做什么才能实现这样的动画?这是我的 xml 代码:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/fragmentContainer"
        android:visibility="gone"/>

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <com.google.android.material.appbar.AppBarLayout
                android:id="@+id/appBarLayout"
                app:layout_constraintTop_toTopOf="parent"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <androidx.appcompat.widget.Toolbar
                    android:layout_width="match_parent"
                    android:layout_height="?actionBarSize"
                    app:navigationIcon="@drawable/left"
                    android:id="@+id/toolbar"
                    app:popupTheme="@style/Theme.MyApplication.PopupMenu">

                    <com.mikhaellopez.circularimageview.CircularImageView
                        android:id="@+id/image"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@mipmap/ic_launcher"
                        app:civ_border="false"
                        android:layout_margin="@dimen/_6sdp"/>

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"
                        android:orientation="vertical"
                        android:paddingStart="@dimen/_10sdp"
                        android:gravity="center_vertical">

                        <TextView
                            android:id="@+id/title"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Telegram"
                            android:textColor="@color/white"
                            android:textStyle="bold"
                            android:textSize="@dimen/_13sdp"/>

                        <View
                            android:layout_width="wrap_content"
                            android:layout_height="@dimen/_3sdp"/>

                        <TextView
                            android:id="@+id/lastSeenTV"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="last seen 1 minute ago"
                            android:textSize="@dimen/_9sdp"
                            android:textColor="@color/white"/>

                    </LinearLayout>

                </androidx.appcompat.widget.Toolbar>

            </com.google.android.material.appbar.AppBarLayout>

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerView"
                app:layout_constraintTop_toBottomOf="@id/appBarLayout"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                app:layout_constraintBottom_toTopOf="@id/bottomBar"
                android:padding="@dimen/_5sdp"
                android:background="#E4E4E4"
                app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
                app:reverseLayout="true"
                />

            <LinearLayout
                android:id="@+id/bottomBar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:minHeight="@dimen/_40sdp"
                android:orientation="vertical"
                app:layout_constraintBottom_toBottomOf="parent">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:minHeight="@dimen/_40sdp"
                    android:orientation="horizontal"
                    android:background="@color/white">

                    <ImageView
                        android:id="@+id/emoji"
                        android:layout_width="@dimen/_23sdp"
                        android:layout_height="@dimen/_23sdp"
                        android:src="@drawable/emoji"
                        app:tint="@android:color/darker_gray"
                        android:layout_gravity="center_vertical"
                        android:layout_marginStart="@dimen/_7sdp"
                        android:background="?selectableItemBackgroundBorderless"/>

                    <com.vanniktech.emoji.EmojiEditText
                        android:id="@+id/message"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:hint="Message"
                        android:maxHeight="@dimen/_100sdp"
                        android:textColorHint="@android:color/darker_gray"
                        android:paddingVertical="@dimen/_7sdp"
                        android:paddingHorizontal="@dimen/_7sdp"
                        android:textColor="@android:color/darker_gray"
                        tools:text="@string/sample_long_text"
                        android:backgroundTint="@android:color/transparent"
                        tools:ignore="HardcodedText" />

                    <ImageView
                        android:id="@+id/send"
                        android:layout_width="@dimen/_23sdp"
                        android:layout_height="@dimen/_23sdp"
                        android:src="@drawable/send"
                        app:tint="@android:color/darker_gray"
                        android:layout_gravity="center_vertical"
                        android:layout_marginHorizontal="@dimen/_7sdp"
                        android:background="?selectableItemBackgroundBorderless"/>

                </LinearLayout>

                </LinearLayout>

        </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

I have an app and I want to animate the keyboard something like this:

OR is the gif is not working, you can go to this url and get the gif.

Please ignore the first image. I am asking about the second one.

What do I need to do to achieve such an animation? This is my xml code:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/fragmentContainer"
        android:visibility="gone"/>

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <com.google.android.material.appbar.AppBarLayout
                android:id="@+id/appBarLayout"
                app:layout_constraintTop_toTopOf="parent"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <androidx.appcompat.widget.Toolbar
                    android:layout_width="match_parent"
                    android:layout_height="?actionBarSize"
                    app:navigationIcon="@drawable/left"
                    android:id="@+id/toolbar"
                    app:popupTheme="@style/Theme.MyApplication.PopupMenu">

                    <com.mikhaellopez.circularimageview.CircularImageView
                        android:id="@+id/image"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@mipmap/ic_launcher"
                        app:civ_border="false"
                        android:layout_margin="@dimen/_6sdp"/>

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"
                        android:orientation="vertical"
                        android:paddingStart="@dimen/_10sdp"
                        android:gravity="center_vertical">

                        <TextView
                            android:id="@+id/title"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Telegram"
                            android:textColor="@color/white"
                            android:textStyle="bold"
                            android:textSize="@dimen/_13sdp"/>

                        <View
                            android:layout_width="wrap_content"
                            android:layout_height="@dimen/_3sdp"/>

                        <TextView
                            android:id="@+id/lastSeenTV"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="last seen 1 minute ago"
                            android:textSize="@dimen/_9sdp"
                            android:textColor="@color/white"/>

                    </LinearLayout>

                </androidx.appcompat.widget.Toolbar>

            </com.google.android.material.appbar.AppBarLayout>

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerView"
                app:layout_constraintTop_toBottomOf="@id/appBarLayout"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                app:layout_constraintBottom_toTopOf="@id/bottomBar"
                android:padding="@dimen/_5sdp"
                android:background="#E4E4E4"
                app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
                app:reverseLayout="true"
                />

            <LinearLayout
                android:id="@+id/bottomBar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:minHeight="@dimen/_40sdp"
                android:orientation="vertical"
                app:layout_constraintBottom_toBottomOf="parent">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:minHeight="@dimen/_40sdp"
                    android:orientation="horizontal"
                    android:background="@color/white">

                    <ImageView
                        android:id="@+id/emoji"
                        android:layout_width="@dimen/_23sdp"
                        android:layout_height="@dimen/_23sdp"
                        android:src="@drawable/emoji"
                        app:tint="@android:color/darker_gray"
                        android:layout_gravity="center_vertical"
                        android:layout_marginStart="@dimen/_7sdp"
                        android:background="?selectableItemBackgroundBorderless"/>

                    <com.vanniktech.emoji.EmojiEditText
                        android:id="@+id/message"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:hint="Message"
                        android:maxHeight="@dimen/_100sdp"
                        android:textColorHint="@android:color/darker_gray"
                        android:paddingVertical="@dimen/_7sdp"
                        android:paddingHorizontal="@dimen/_7sdp"
                        android:textColor="@android:color/darker_gray"
                        tools:text="@string/sample_long_text"
                        android:backgroundTint="@android:color/transparent"
                        tools:ignore="HardcodedText" />

                    <ImageView
                        android:id="@+id/send"
                        android:layout_width="@dimen/_23sdp"
                        android:layout_height="@dimen/_23sdp"
                        android:src="@drawable/send"
                        app:tint="@android:color/darker_gray"
                        android:layout_gravity="center_vertical"
                        android:layout_marginHorizontal="@dimen/_7sdp"
                        android:background="?selectableItemBackgroundBorderless"/>

                </LinearLayout>

                </LinearLayout>

        </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文